Cannot Call Validation Data from Another Python File

Hello,

I created a model from Nvidia Modulus based on a PDE. Now I want to validate my results with data that I imported from another Python file.

This is the error message I am getting

c = c_A(to_absolute_path())
TypeError: ‘numpy.ndarray’ object is not callable"

This is the extra lines of code I added for the validation data:

from file_XX import c_A
c = c_A(to_absolute_path())
outvar_numpy = {“c”: c},
validator = PointwiseValidator(
nodes=nodes,
invar=invar_numpy,
true_outvar=c
plotter=ValidatorPlotter(),
)
domain.add_validator(validator, “val_data”)

I don’t understand what is the error in my code. I’ve been looking at other examples and tried their methods too.

Hi @nga77

What is the type of c_A?

to_absolute_path() is a function that will, given a directory, will prepend the run path. You can have a look at the code here.

So I believe

  1. you should be passing in some string to to_absolute_path() otherwise it will return just an empty object.
  2. c_A should be expecting a string, whatever type of object it is, based on your code here. Although I’m not sure I’m following why you want this to happen.

Dear ngeneva,

c_a are the concentration values that I am importing from another python file.
It is of a floating type.
This is the only validation data I am using.

Previously, I modeled a PDE of how concentration varies with time and distance. That worked.
Now, I want to validate my results by importing already computed concentration data from another python file.

I read about the use of the to_absolute_path function, and realized that was not needed for my case.
So, I changed my code to the following:

#add validation data
cA = dict(enumerate(c_A.flatten(),1))
c = str(cA.values()) #convert dict values to string
#cA = dict(enumerate(c_A.flatten(),1))
#c = str(cA.values()) gave error "invalid data type ‘str’. Without it, gave error “must be real number, not dict”
outvar_numpy = {“c”: c}
validator = PointwiseValidator(
nodes=nodes,
invar=invar_numpy,
true_outvar=outvar_numpy,
batch_size=10,
#100 floating elements in c_A array
plotter=ValidatorPlotter(),
)
domain.add_validator(validator, “val_data”)

Now I get the following error message:

[19:25:51] - JIT using the NVFuser TorchScript backend
[19:25:51] - JitManager: {‘_enabled’: True, ‘_arch_mode’: <JitArchMode.ONLY_ACTIVATION: 1>, ‘_use_nvfuser’: True, ‘_autograd_nodes’: False}
[19:25:51] - GraphManager: {‘_func_arch’: False, ‘_debug’: False, ‘_func_arch_allow_partial_hessian’: True}
Error executing job with overrides:
Traceback (most recent call last):
File “PFR_Val.py”, line 189, in run
validator = PointwiseValidator(
File “/modulus/modulus/domain/validator/continuous.py”, line 52, in init
self.dataset = DictPointwiseDataset(invar=invar, outvar=true_outvar)
File “/modulus/modulus/dataset/continuous.py”, line 35, in init
super().init(invar=invar, outvar=outvar, lambda_weighting=lambda_weighting)
File “/modulus/modulus/dataset/dataset.py”, line 98, in init
self.outvar = Dataset._to_tensor_dict(outvar)
File “/modulus/modulus/dataset/dataset.py”, line 49, in _to_tensor_dict
tensor_dict = {
File “/modulus/modulus/dataset/dataset.py”, line 50, in
key: torch.as_tensor(value, dtype=tf_dt, device=device)
TypeError: new(): invalid data type ‘str’

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

Hi @nga77

The parameter true_outvar should be a dictionary of numpy arrays of size [N, 1] (seems your are feeding in a dictionary with a string value). Please refer to the API documentation here.

Thank you so much! That helped