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

Minior updates to calibrate, simulate #108

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions service/models/operations/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import socket
import logging

from typing import ClassVar, Optional
from typing import ClassVar, Optional, Any, Dict
from pydantic import BaseModel, Field, Extra

from pika.exceptions import AMQPConnectionError
Expand All @@ -25,19 +25,12 @@ class CalibrateExtra(BaseModel):
num_iterations: int = Field(
1000, description="Optional field for CIEMSS calibration", example=1000
)
lr: float = Field(
0.03, description="Optional field for CIEMSS calibration", example=0.03
)
verbose: bool = Field(
False, description="Optional field for CIEMSS calibration", example=False
)
num_particles: int = Field(
1, description="Optional field for CIEMSS calibration", example=1
)
# autoguide: pyro.infer.autoguide.AutoLowRankMultivariateNormal
solver_method: str = Field(
"dopri5", description="Optional field for CIEMSS calibration", example="dopri5"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we making these changes? Have we consider the impact and the types of corresponding changes we need to make?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are a result of the changes requested here: DARPA-ASKEM/terarium#4201



class Calibrate(OperationRequest):
Expand All @@ -46,6 +39,18 @@ class Calibrate(OperationRequest):
dataset: Dataset = None
timespan: Optional[Timespan] = None
policy_intervention_id: str = Field(None, example="ba8da8d4-047d-11ee-be56")
learning_rate: float = Field(
0.03, description="Optional field for CIEMSS calibration", example=0.03
)
solver_method: str = (
Field(
"dopri5",
description="Optional field for CIEMSS calibration",
example="dopri5",
),
)
# https://github.com/ciemss/pyciemss/blob/main/pyciemss/integration_utils/interface_checks.py
solver_options: Dict[str, Any] = ({},)
extra: CalibrateExtra = Field(
None,
description="optional extra system specific arguments for advanced use cases",
Expand Down Expand Up @@ -74,6 +79,8 @@ def hook(progress, _loss):
logging.info(f"Calibration is {progress}% complete")
return None

extra_options = self.extra.dict()

return {
"model_path_or_json": amr_path,
"start_time": self.timespan.start,
Expand All @@ -82,8 +89,11 @@ def hook(progress, _loss):
"data_path": dataset_path,
"static_parameter_interventions": static_interventions,
"progress_hook": hook,
"lr": self.learning_rate,
"solver_method": self.solver_method,
"solver_options": self.solver_options,
# "visual_options": True,
**self.extra.dict(),
**extra_options,
}

class Config:
Expand Down
14 changes: 12 additions & 2 deletions service/models/operations/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from typing import ClassVar, Optional
from pydantic import BaseModel, Field, Extra


from typing import Dict, Any
from models.base import OperationRequest, Timespan
from models.converters import (
fetch_and_convert_static_interventions,
Expand All @@ -28,6 +27,15 @@ class Simulate(OperationRequest):
model_config_id: str = Field(..., example="ba8da8d4-047d-11ee-be56")
timespan: Timespan = Timespan(start=0, end=90)
policy_intervention_id: str = Field(None, example="ba8da8d4-047d-11ee-be56")
solver_method: str = (
Field(
"dopri5",
description="Optional field for CIEMSS calibration",
example="dopri5",
),
)
# https://github.com/ciemss/pyciemss/blob/main/pyciemss/integration_utils/interface_checks.py
solver_options: Dict[str, Any] = ({},)
step_size: float = 1.0
extra: SimulateExtra = Field(
None,
Expand Down Expand Up @@ -59,6 +67,8 @@ def gen_pyciemss_args(self, job_id):
"static_parameter_interventions": static_interventions,
"dynamic_parameter_interventions": dynamic_interventions,
"inferred_parameters": inferred_parameters,
"solver_method": self.solver_method,
"solver_options": self.solver_options,
**extra_options,
}

Expand Down
6 changes: 3 additions & 3 deletions tests/examples/calibrate/input/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"start": 0,
"end": 90
},
"learning_rate": 0.3,
"solver_method": "dopri5",
"extra": {
"num_samples": 100,
"start_time": -1e-10,
"num_iterations": 1000,
"lr": 0.03,
"verbose": false,
"num_particles": 1,
"method": "dopri5"
"num_particles": 1
}
}
Loading