Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot save a TemplateModel with distribution parameter expressions as a AMR #369

Closed
liunelson opened this issue Sep 19, 2024 · 2 comments
Closed

Comments

@liunelson
Copy link

I have this model:
model_seirhd.json

I edited its parameters to try out the new distribution parameter feature:

new_parameters = {
    'u': Parameter(
        name = 'u', 
        display_name = 'u', 
        description = 'Population count uncertainty', 
        value = 1.0
    ),
    'b_shape': Parameter(
        name = 'b_shape', display_name = 'b_shape', description = 'Beta distribution shape parameter for the parameter "b"', 
        distribution = Distribution(
            type = 'Beta1', 
            parameters = {
                'alpha': sympy.Integer(1),
                'beta': sympy.Integer(10)
            }
        )
    ),
    'p_u': Parameter(
        name = 'p_u', 
        display_name = 'p_u', 
        description = 'Percent uncertainty on probability transitions', 
        value = 0.10
    )
}

model.parameters = model.parameters | new_parameters
model.parameters['b'] = Parameter(
    name = 'b',
    display_name = 'b',
    description = 'Infection rate',
    distribution = Distribution(
        type = 'InverseGamma1',
        parameters = {
            'shape': sympy.Symbol('b_shape') ** sympy.Float(1.5),
            'scale': 0.01
        }
    )
)

for p in model.parameters.keys():
    if p[0] == "r":
        v = model.parameters[p].value
        model.parameters[p].distribution.parameters = {
            'minimum': sympy.Float(v) - sympy.Symbol('u'),
            'maximum': sympy.Float(v) + sympy.Symbol('u')
        }

I get this error when I try to serialize the model:
Screenshot 2024-09-19 at 5 23 49 PM

It seems that template_model_to_petri_json did not generate a string representation of the sympy.core.add.Add object in all the r* distribution parameters.

@bgyori
Copy link
Member

bgyori commented Sep 19, 2024

These have to be objects of type SympyExprStr, not simple sympy.Expr. So e.g.,

'shape': SympyExprStr(sympy.Symbol('b_shape') ** sympy.Float(1.5)),

@liunelson
Copy link
Author

Thanks, adding SympyExpStr to all the expressions fixed all the serialization errors that I had!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants