pabloprf / MITIM-fusion

MITIM (MIT Integrated Modeling) Suite for Fusion Applications
https://mitim-fusion.readthedocs.io
MIT License
10 stars 4 forks source link

Error in running portals #28

Open jmcclena opened 3 days ago

jmcclena commented 3 days ago

I'm getting the fallowing error when running portals. @pabloprf any idea what could cause it?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/portals_qlgyro/PORTALS_workflow.py:46
     44 print("restart=",restart)
     45 prf_bo = STRATEGYtools.PRF_BO(portals_fun, restartYN=restart, askQuestions=False)
---> 46 prf_bo.run()
     48 # Plot
     49 portals_fun.plot_optimization_results(analysis_level=4)

File ~/MITIM-fusion/src/mitim_tools/opt_tools/STRATEGYtools.py:807, in PRF_BO.run(self)
    804 self.avoidPoints = np.unique([int(j) for j in avoidPoints])
    806 # ***** Fit
--> 807 self.steps[-1].fit_step(avoidPoints=self.avoidPoints)
    809 # Store class with the model fitted
    810 if self.storeClass:

File ~/MITIM-fusion/src/mitim_tools/opt_tools/STEPtools.py:252, in OPTstep.fit_step(self, avoidPoints, fitWithTrainingDataIfContains)
    236     GP = SURROGATEtools.surrogate_model(
    237         x,
    238         y,
   (...)
    248         fileTraining=fileTraining,
    249     )
    251     # Fitting
--> 252     GP.fit()
    254     self.GP["individual_models"][i] = GP
    256 if os.path.exists(fileTraining+".bak"):

File ~/MITIM-fusion/src/mitim_tools/opt_tools/SURROGATEtools.py:387, in surrogate_model.fit(self)
    385 # Train always in physics-transformed space, to enable mitim re-use training from file
    386 with fundamental_model_context(self):
--> 387     track_fval = self.perform_model_fit(mll)
    389 # ---------------------------------------------------------------------------------------------------
    390 # Asses optimization
    391 # ---------------------------------------------------------------------------------------------------
    392 self.assess_optimization(track_fval)

File ~/MITIM-fusion/src/mitim_tools/opt_tools/SURROGATEtools.py:426, in surrogate_model.perform_model_fit(self, mll)
    418     print(
    419         f"\t* Using approximate MLL because x has {len(train_x)} elements",
    420         verbose=read_verbose_level(),
    421     )
    422 # --------------------------------------------------
    423 
    424 # Store first MLL value
    425 track_fval = [
--> 426     -mll.forward(mll.model(*mll.model.train_inputs), mll.model.train_targets)
    427     .detach()
    428     .item()
    429 ]
    431 def callback(x, y, mll=mll):
    432     track_fval.append(y.fval)

File ~/mitim-env/lib/python3.10/site-packages/gpytorch/models/exact_gp.py:268, in ExactGP.__call__(self, *args, **kwargs)
    264         if not all(
    265             torch.equal(train_input, input) for train_input, input in length_safe_zip(train_inputs, inputs)
    266         ):
    267             raise RuntimeError("You must train on the training inputs!")
--> 268     res = super().__call__(*inputs, **kwargs)
    269     return res
    271 # Prior mode

File ~/mitim-env/lib/python3.10/site-packages/gpytorch/module.py:31, in Module.__call__(self, *inputs, **kwargs)
     30 def __call__(self, *inputs, **kwargs) -> Union[Tensor, Distribution, LinearOperator]:
---> 31     outputs = self.forward(*inputs, **kwargs)
     32     if isinstance(outputs, list):
     33         return [_validate_module_outputs(output) for output in outputs]

File ~/mitim-env/lib/python3.10/site-packages/botorch/models/gp_regression.py:214, in SingleTaskGP.forward(self, x)
    212     x = self.transform_inputs(x)
    213 mean_x = self.mean_module(x)
--> 214 covar_x = self.covar_module(x)
    215 return MultivariateNormal(mean_x, covar_x)

File ~/mitim-env/lib/python3.10/site-packages/torch/nn/modules/module.py:1729, in Module.__getattr__(self, name)
   1727     if name in modules:
   1728         return modules[name]
-> 1729 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")

AttributeError: 'ExactGPcustom' object has no attribute 'covar_module'
pabloprf commented 3 days ago

What are your versions of botorch, gpytorch and torch?

jmcclena commented 3 days ago
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import botorch, gpytorch,torch
>>> botorch.__version__
'0.9.4'
>>> gpytorch.__version__
'1.11'
>>> torch.__version__
'2.4.1+cu121'
pabloprf commented 3 days ago

Ok, versions look good. Are you creating your custom namelist and redefining TypeKernel? I'm suspicious that TypeKernel is not between 0 and 3, and that's causing that self.covar_module is never defined as part of the ExactGPcustom class that you can find in mitim_tools.opt_tools.BOTORCHtools