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 all 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
32 changes: 24 additions & 8 deletions service/models/operations/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,21 @@ 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_step_size: float = Field(
None,
description="id from a previous calibration",
example=1.0,
)
extra: CalibrateExtra = Field(
None,
description="optional extra system specific arguments for advanced use cases",
Expand Down Expand Up @@ -74,6 +82,11 @@ def hook(progress, _loss):
logging.info(f"Calibration is {progress}% complete")
return None

extra_options = self.extra.dict()
solver_options = {}
if self.solver_step_size is not None:
solver_options = {"step_size": self.solver_step_size}

return {
"model_path_or_json": amr_path,
"start_time": self.timespan.start,
Expand All @@ -82,8 +95,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": solver_options,
# "visual_options": True,
**self.extra.dict(),
**extra_options,
}

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

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


from models.base import OperationRequest, Timespan
from models.converters import (
fetch_and_convert_static_interventions,
Expand All @@ -28,7 +26,18 @@ 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")
step_size: float = 1.0
solver_method: str = Field(
"dopri5",
description="Optional field for CIEMSS calibration",
example="dopri5",
)
logging_step_size: float = 1.0
# https://github.com/ciemss/pyciemss/blob/main/pyciemss/integration_utils/interface_checks.py
solver_step_size: float = Field(
None,
description="id from a previous calibration",
example=1.0,
)
extra: SimulateExtra = Field(
None,
description="optional extra system specific arguments for advanced use cases",
Expand All @@ -51,14 +60,20 @@ def gen_pyciemss_args(self, job_id):
extra_options.pop("inferred_parameters"), job_id
)

solver_options = {}
if self.solver_step_size is not None:
solver_options = {"step_size": self.solver_step_size}

return {
"model_path_or_json": amr_path,
"logging_step_size": self.step_size,
"logging_step_size": self.logging_step_size,
"start_time": self.timespan.start,
"end_time": self.timespan.end,
"static_parameter_interventions": static_interventions,
"dynamic_parameter_interventions": dynamic_interventions,
"inferred_parameters": inferred_parameters,
"solver_method": self.solver_method,
"solver_options": 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