I downloaded the GamsPy and activated with the academic license. Once I tried to copy quick start guide model in https://gamspy.readthedocs.io/en/latest/user/notebooks/trnsport.html, first it worked. In my second run, it gave valueError. Interestingly, if I run the same cell for 10 times, it works 2 times and raises an error for the rest. Is there a solution for this one? Or what is the potential reason for this issue? I believe it is a problem with a private class object. See the error attached.
I tried to reproduce the error but failed to do so. Can you explain what you did step by step? It would also be really helpful if you can share the stack trace.
I ran the first two cells and ran the third cell 10 times but it didn’t produce any errors.
Thank you for the fast reply Muhammet. I just copied the whole code to a py file and works well. However in the jupyter notebook it still produces the same error. You can find the stack trace attached. Kind regards,
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[45], line 3
1 m = Container()
----> 3 i = Set(container=m, name="i", description="plants")
4 j = Set(container=m, name="j", description="markets")
File ~/anaconda3/envs/uon/lib/python3.11/site-packages/gamspy/_symbols/set.py:651, in Set.__init__(self, container, name, domain, is_singleton, records, domain_forwarding, description, uels_on_axes, is_miro_input, is_miro_output)
649 self.setRecords(records, uels_on_axes=uels_on_axes)
650 else:
--> 651 self.container._synch_with_gams()
653 container._options.miro_protect = previous_state
File ~/anaconda3/envs/uon/lib/python3.11/site-packages/gamspy/_container.py:537, in Container._synch_with_gams(self, keep_flags)
535 def _synch_with_gams(self, keep_flags: bool = False) -> DataFrame | None:
536 runner = backend_factory(self, self._options)
--> 537 summary = runner.run(keep_flags=keep_flags)
539 if self._options and self._options.seed is not None:
540 # Required for correct seeding. Seed can only be set in the first run.
541 self._options.seed = None
File ~/anaconda3/envs/uon/lib/python3.11/site-packages/gamspy/_backend/local.py:91, in Local.run(self, keep_flags)
88 gams_string = self.preprocess(self.container._gdx_in, keep_flags)
90 # Run the model
---> 91 self.execute_gams(gams_string)
93 # Synchronize GAMSPy with checkpoint and return a summary
94 summary = self.postprocess()
File ~/anaconda3/envs/uon/lib/python3.11/site-packages/gamspy/_backend/local.py:105, in Local.execute_gams(self, gams_string)
103 # Write pf file
104 extra_options = self._prepare_extra_options(self.job_name)
--> 105 self.options._set_extra_options(extra_options)
107 self.options._export(self.pf_file, self.output)
109 try:
File ~/anaconda3/envs/uon/lib/python3.11/site-packages/gamspy/_options.py:438, in Options._set_extra_options(self, options)
436 def _set_extra_options(self, options: dict) -> None:
437 """Set extra options of the backend"""
--> 438 self._extra_options = options
File ~/anaconda3/envs/uon/lib/python3.11/site-packages/pydantic/main.py:357, in pydantic.main.BaseModel.__setattr__()
ValueError: "Options" object has no field "_extra_options"
Looks like Pydantic does not allow the private attribute assignment. Can you run pip list
to see the version of Pydantic you are using? GAMSPy requires at least pydantic 2.0.
I checked and I have pydantic 2.9.0. Today I tried the run the same snippet again and it is working . I dont know what is or what was the problem because I haven’t changed anything since friday. I will let you know if this will happen again. Seems like stable at the moment.