Skip to content

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

@liunelson

Description

@liunelson

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"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions