Skip to content

Serialization doesn't always work #126

Open
1 of 1 issue completed
Open

Description

@henrikjacobsenfys

For example, I just got this error when trying to copy a SampleModel:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[13], [line 2](vscode-notebook-cell:?execution_count=13&line=2)
      1 # Now make a new analysis with this sample model
----> [2](vscode-notebook-cell:?execution_count=13&line=2) mag_sample_model = copy(sample_model)
      3 DHO1 = DampedHarmonicOscillator(display_name = 'DHO1', area=100, center=0.2, width=0.2)
      4 DHO2 = DampedHarmonicOscillator(display_name = 'DHO2', area=10, center=1.1, width=0.2)

File ~\Documents\easyScience\dynamics-lib\.pixi\envs\default\Lib\copy.py:79, in copy(x)
     77 copier = getattr(cls, "__copy__", None)
     78 if copier is not None:
---> [79](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/henrikjacobsen3/Documents/easyScience/dynamics-lib/docs/docs/tutorials/~/Documents/easyScience/dynamics-lib/.pixi/envs/default/Lib/copy.py:79)     return copier(x)
     81 reductor = dispatch_table.get(cls)
     82 if reductor is not None:

File ~\Documents\easyScience\dynamics-lib\.pixi\envs\default\Lib\site-packages\easyscience\base_classes\new_base.py:138, in NewBase.__copy__(self)
    136 """Return a copy of the object."""
    137 temp = self.to_dict(skip=['unique_name'])
--> [138](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/henrikjacobsen3/Documents/easyScience/dynamics-lib/docs/docs/tutorials/~/Documents/easyScience/dynamics-lib/.pixi/envs/default/Lib/site-packages/easyscience/base_classes/new_base.py:138) new_obj = self.__class__.from_dict(temp)
    139 return new_obj

File ~\Documents\easyScience\dynamics-lib\.pixi\envs\default\Lib\site-packages\easyscience\base_classes\model_base.py:108, in ModelBase.from_dict(cls, obj_dict)
    106         parameter_placeholder[key] = value
    107         kwargs[key] = value.value
--> [108](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/henrikjacobsen3/Documents/easyScience/dynamics-lib/docs/docs/tutorials/~/Documents/easyScience/dynamics-lib/.pixi/envs/default/Lib/site-packages/easyscience/base_classes/model_base.py:108) cls_instance = cls(**kwargs)
...
     81     )
     83 self._components = ComponentCollection()
     84 if isinstance(components, (ModelComponent, ComponentCollection)):

TypeError: Components must be a ModelComponent, a ComponentCollection or None, got list

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    [scope] bug
    [priority] high
    on Mar 10, 2026
  2. henrikjacobsenfys commented on Apr 22, 2026

    @henrikjacobsenfys
    MemberAuthor

    Worse, SampleModel does not respect all bounds from the template components. This is because the mixin class that creates parameters sets the .min value of various parameters to either 0 or a very small number. This happens in __init__ and overwrites the .min the parameter already had.

  3. added a commit that references this issue on Nov 12, 2026
    7eba8d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [priority] high[scope] bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions