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

[BUG]: Error with pyciemss.sample when given model with an observable #634

Open
liunelson opened this issue Nov 27, 2024 · 1 comment
Open
Assignees

Comments

@liunelson
Copy link
Contributor

When I try to run this model with pyciemss.sample, I get a TypeError.
SIR_with_observable.json

If I remove the observables, then it runs without issue.

start_time = 0.0
end_time = 40.0
logging_step_size = 1.0
num_samples = 1

result_preoptimize = pyciemss.sample(
    template_model_to_petrinet_json(model),
    end_time,
    logging_step_size,
    num_samples,
    start_time = start_time,
    solver_method = "dopri5"
)
File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:909, in singledispatch.<locals>.wrapper(*args, **kw)
    [905](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:905) if not args:
    [906](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:906)     raise TypeError(f'{funcname} requires at least '
    [907](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:907)                     '1 positional argument')
--> [909](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:909) return dispatch(args[0].__class__)(*args, **kw)

File ~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:34, in _append_trajectory(traj1, traj2)
     [29](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:29) if traj1.keys() != traj2.keys():
     [30](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:30)     raise ValueError(
     [31](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:31)         f"Trajectories must have the same keys to be appended, but got {traj1.keys()} and {traj2.keys()}."
     [32](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:32)     )
---> [34](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:34) return type(traj1)(**{k: append(traj1[k], traj2[k]) for k in traj1.keys()})

File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:909, in singledispatch.<locals>.wrapper(*args, **kw)
    [905](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:905) if not args:
    [906](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:906)     raise TypeError(f'{funcname} requires at least '
    [907](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:907)                     '1 positional argument')
--> [909](https://file+.vscode-resource.vscode-cdn.net/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py:909) return dispatch(args[0].__class__)(*args, **kw)

File ~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:42, in _append_tensor(prev_v, curr_v)
     [40](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:40) batch_shape = torch.broadcast_shapes(prev_v.shape[:-1], curr_v.shape[:-1])
     [41](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:41) prev_v = prev_v.expand(*batch_shape, *prev_v.shape[-1:])
---> [42](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:42) curr_v = curr_v.expand(*batch_shape, *curr_v.shape[-1:])
     [43](https://file+.vscode-resource.vscode-cdn.net/Users/nliu/Workspace/projects/uncharted/askem/pyciemss/~/Workspace/projects/uncharted/askem/pyciemss/.venv/lib/python3.12/site-packages/chirho/dynamical/internals/_utils.py:43) return torch.cat([prev_v, curr_v], dim=time_dim)

TypeError: expand() missing 1 required positional arguments: "size"
@sabinala
Copy link
Contributor

@SamWitty this is very odd, but what we have found is that if all of the observables are only expressions of parameters, we will get an error, like those in: https://github.com/ciemss/pyciemss/blob/sa-634-bug-error-with-pyciemsssample-when-given-model-with-an-observable-1/docs/source/Issue-634.ipynb.

However, if any one of the observables contains a state variable in the expression, it will simulate just fine.

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

When branches are created from issues, their pull requests are automatically linked.

2 participants