Skip to content

Commit

Permalink
Merge branch 'hackathon_fall_2023' of https://github.com/siftech/funman
Browse files Browse the repository at this point in the history
… into hackathon_fall_2023
  • Loading branch information
danbryce committed Nov 29, 2023
2 parents 1c95da1 + 4fb1c5f commit d662b74
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(
alpha=0.2,
plot_points=False,
parameters=None,
dpi=100,
):
if isinstance(parameter_space, ParameterSpace):
self.ps = parameter_space
Expand Down Expand Up @@ -55,6 +56,7 @@ def __init__(
Line2D([0], [0], color="g", lw=4, alpha=alpha),
Line2D([0], [0], color="r", lw=4, alpha=alpha),
]
self.dpi = dpi

def computeBounds(self, interval: Interval = Interval(lb=-2000, ub=2000)):
box = Box(bounds={p: interval for p in self.parameters})
Expand All @@ -68,7 +70,7 @@ def initialize_figure(self):
self.dim,
self.dim,
squeeze=False,
dpi=600,
dpi=self.dpi,
figsize=(10, 10),
)
self.fig = fig
Expand Down
1 change: 0 additions & 1 deletion resources/cached/068cef77-839d-49be-9191-3502ee6d5240.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@
"num_steps": 2,
"step_size": 1,
"num_initial_boxes": 1,
"save_smtlib": "my.smt2",
"dreal_precision": 0.001,
"dreal_log_level": "off",
"constraint_noise": 0.0,
Expand Down
22 changes: 11 additions & 11 deletions scratch/hackathon/hackathon_fall_2023_demo_terarrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def main():
"name": "epsilon",
"interval": {
"lb": 0.1368,
# "ub": 0.20520000000000002
"ub": 0.18,
"ub": 0.20520000000000002
# "ub": 0.18,
},
"label": "all",
},
Expand Down Expand Up @@ -109,8 +109,8 @@ def main():
"name": "theta",
"interval": {
"lb": 0.2968,
# "ub": 0.4452
"ub": 0.4,
"ub": 0.4452
# "ub": 0.4,
},
"label": "all",
},
Expand Down Expand Up @@ -180,7 +180,7 @@ def main():
# {
# "name": "infected_maximum1",
# "variable": "Infected",
# "interval": {"lb": 0.0, "ub":0.1},
# "interval": {"lb": 1e-5},
# "timepoints": {"lb": 10, "ub": 10, "closed_upper_bound": True},
# },
# {
Expand Down Expand Up @@ -236,21 +236,21 @@ def main():
210,
]
}
# {"timepoints": [0, 10]}
# {"timepoints": [0, 10, 20]}
],
}
],
"config": {
"use_compartmental_constraints": True,
"normalization_constant": 1.0,
"tolerance": 0.1,
"tolerance": 0.2,
"verbosity": 10,
"dreal_mcts": True,
"save_smtlib": os.path.join(os.path.realpath(__file__), "./out"),
"save_smtlib": os.path.join(os.path.dirname(__file__), "./out"),
"substitute_subformulas": False,
"series_approximation_threshold": None,
"dreal_log_level": "info",
"dreal_precision": 1,
"dreal_log_level": "none",
"dreal_precision": 1e-1,
"profile": False,
},
}
Expand All @@ -261,7 +261,7 @@ def main():
request_dict,
# REQUEST_PATH,
description="SIDARTHE demo",
case_out_dir="./out",
case_out_dir=os.path.join(os.path.dirname(__file__), "./out"),
dump_plot=True,
parameters_to_plot=["theta", "epsilon", "timestep"],
point_plot_config={
Expand Down
38 changes: 20 additions & 18 deletions src/funman/api/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,15 @@ def run_instance(
with open(outfile, "w") as f:
f.write(results.model_dump_json(by_alias=True))
if dump_plot:
point_plot_filename = (
f"{out_dir}/{work_unit.id}_points.png"
)

points = results.parameter_space.points()
if len(points) > 0:
point_plot_filename = (
f"{out_dir}/{work_unit.id}_points.png"
)
l.info(
f"Creating plot of point trajectories: {point_plot_filename}"
f"Creating plot of point trajectories: {point_plot_filename}"
)

points_to_plot = (
random.choices(
points, k=min(len(points), num_points)
Expand All @@ -278,19 +278,21 @@ def run_instance(
plt.savefig(point_plot_filename)
plt.close()

space_plot_filename = (
f"{out_dir}/{work_unit.id}_parameter_space.png"
)
l.info(
f"Creating plot of parameter space: {space_plot_filename}"
)
ParameterSpacePlotter(
results.parameter_space,
plot_points=False,
parameters=parameters_to_plot,
).plot(show=True)
plt.savefig(space_plot_filename)
plt.close()
boxes = results.parameter_space.boxes()
if len(boxes) > 0:
space_plot_filename = (
f"{out_dir}/{work_unit.id}_parameter_space.png"
)
l.info(
f"Creating plot of parameter space: {space_plot_filename}"
)
ParameterSpacePlotter(
results.parameter_space,
plot_points=False,
parameters=parameters_to_plot,
).plot(show=False)
plt.savefig(space_plot_filename)
plt.close()
sleep(10)
else:
results = self._worker.get_results(work_unit.id)
Expand Down
7 changes: 7 additions & 0 deletions src/funman/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
analysis.
"""
import logging
import os
from typing import Optional, Union

from pydantic import BaseModel, ConfigDict, field_validator, model_validator
Expand Down Expand Up @@ -106,4 +107,10 @@ def check_use_compartmental_constraints(self) -> "FUNMANConfig":
assert (
self.normalization_constant
), "Need to set normalization_constant in configuration to enforce compartmental constraints. The normalization_constant provides the population size used in the constraint upper bound."

if self.save_smtlib:
assert os.path.exists(
os.path.dirname(self.save_smtlib)
), "save_smtlib option must be an existing path"

return self
Loading

0 comments on commit d662b74

Please sign in to comment.