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

Calibrate does not parse expressions #468

Closed
mwdchang opened this issue Feb 1, 2024 · 2 comments · Fixed by #491
Closed

Calibrate does not parse expressions #468

mwdchang opened this issue Feb 1, 2024 · 2 comments · Fixed by #491
Labels
bug Something isn't working integration Tasks for integration with TA4

Comments

@mwdchang
Copy link

mwdchang commented Feb 1, 2024

This arose from pytorch errors during calibrate operations:

ERROR:root:
        ###############################

        There was an exception in CIEMSS Service

        job: e117565e-3f76-497d-a337-85c53dc4d136
        <class 'ValueError'>: Expected parameter loc (Tensor of shape (4,)) of distribution LowRankMultivariateNormal(loc: torch.Size([4]), cov_factor: torch.Size([4, 2]), cov_diag: torch.Size([4])) to satisfy the constraint IndependentConstraint(Real(), 1), but found invalid values:
tensor([nan, nan, nan, nan], grad_fn=<SelectBackward0>)
             Trace Shapes:
              Param Sites:
     AutoGuideList.1.scale   4
AutoGuideList.1.cov_factor 4 2
       AutoGuideList.1.loc   4
             Sample Sites:
        ################################

Using the SIR petrinet (https://github.com/DARPA-ASKEM/Model-Representations/blob/main/petrinet/examples/sir.json) as an example here, it seems like if the state initials are not literals, the calibrate operation will fail. For example if S is specified as S0-expression:

        {
          "target": "S",
          "expression": "S0",
          "expression_mathml": "<ci>S0</ci>"
        },

But when the expression is a literal, then it works (at least there's no errors in the log) and a dill file was created.

        {
          "target": "S",
          "expression": "1000.00001",
          "expression_mathml": "<ci>1000.00001</ci>"
        },

Moreover if the literal is not a float - e.g. if I use 1000 instead of 1000.00001 that also lead to a failed calibrate: TypeError: y0 must be a floating point Tensor but is a torch.LongTensor

@SamWitty
Copy link
Contributor

SamWitty commented Feb 14, 2024

@mwdchang , I'm able to reproduce this (and similar shape mismatch) errors using this AMR, but I'm having a bit of trouble understanding the root cause. The thing that is perplexing is that we have other models in our tests that are successfully simulating, calibrating, etc. that have expressions for initials. For example, see the expression total_population-I0 for the initial value of "S" in https://raw.githubusercontent.com/DARPA-ASKEM/simulation-integration/main/data/models/SEIRHD_NPI_Type1_petrinet.json

Do you notice anything else different about these two files that might indicate what the issue is?

@mwdchang
Copy link
Author

@SamWitty this is quite strange indeed - now that you are reproducing the error, I no longer see the torch problem anymore (with the SIR model in my link above). I also tried the SEIRHD in your message and that went through calibration as well.

I am running a new build of pyciemss-service as @fivegrant added some refactoring changes earlier today. However, building against the latest, as well as the commit I was using before seem to be okay now. And I imagine you are testing against pyciemss directly rather than pyciemss-service?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working integration Tasks for integration with TA4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants