Skip to content

-1*param is serialized as -param #59

@m-prl

Description

@m-prl

When the symbolic expressions are serialized, -1*param is stored as -param in the impact models, which sometimes cannot be deserialized back into a symbolic expression.
This can lead to an invalid_expr when loading the model.

Traceback (most recent call last):
  File "C:\repositories\demo\run_impact_model.py", line 3, in <module>
    model = ImpactModel.from_yaml("data/impact_model.yaml")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\repositories\demo\.venv\Lib\site-packages\apparun\impact_model.py", line 176, in from_yaml
    return ImpactModel.from_dict(impact_model)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\repositories\demo\.venv\Lib\site-packages\apparun\impact_model.py", line 148, in from_dict
    tree=ImpactTreeNode.from_dict(impact_model["tree"]),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\repositories\demo\.venv\Lib\site-packages\apparun\impact_tree.py", line 138, in from_dict
    node = ImpactTreeNode(
           ^^^^^^^^^^^^^^^
  File "C:\repositories\demo\.venv\Lib\site-packages\pydantic\main.py", line 250, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for ImpactTreeNode
models
   [type=invalid_expr, input_value={'EFV3_CLIMATE_CHANGE': '... 21.707425626610416)))'}, input_type=dict]

A workaround is to manually replace each occurrence of -param by -1*param in the impact model.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions