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

v1.10.0 #50

Merged
merged 115 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
54ef23e
add simulation to check points in consistency problems
danbryce May 23, 2024
be1d430
SIDARTHE original unit test
dmosaphir Jul 31, 2024
608db52
SIDARTHE step function unit test
dmosaphir Jul 31, 2024
50bb68a
AMRs for Aug2024 demo
dmosaphir Jul 31, 2024
ad25e26
AMR - Aug 2024 demo
dmosaphir Jul 31, 2024
d4bd565
change theme for docs to avoid dep conflict
danbryce Aug 5, 2024
13cc0e5
setup demo
danbryce Aug 7, 2024
80978ef
SIDARTHE original unit test
dmosaphir Aug 7, 2024
5343b7b
SIDARTHE step function unit test
dmosaphir Aug 7, 2024
0c9e7a0
AMRs for Aug2024 demo
dmosaphir Aug 7, 2024
0476184
AMR - Aug 2024 demo
dmosaphir Aug 7, 2024
d5994a1
setup demo
danbryce Aug 7, 2024
4551053
upgrade build
danbryce Aug 7, 2024
0e6cd76
use cpp 3.10 for dreal wheel
danbryce Aug 14, 2024
a02ff63
update usage of pandas to infer_objects
danbryce Aug 14, 2024
c9a465a
scenarios
danbryce Aug 19, 2024
939cfca
Merge commit '13cc0e58f61ead9150b513f986ea21b51ca72043' into develop
danbryce Aug 19, 2024
d8dc556
updated nbs
danbryce Aug 19, 2024
63dde37
fix tests (asym meets, None values in points)
danbryce Aug 20, 2024
cd0c599
Merge branch 'develop' into july-monthly-demo
danbryce Aug 20, 2024
22a9a70
move notes sources
danbryce Aug 21, 2024
95286e2
build updates
danbryce Aug 23, 2024
dbc3be2
improve dataframe generation
danbryce Aug 23, 2024
255776c
Merge branch 'simulate' into july-monthly-demo
danbryce Aug 23, 2024
87132a0
add flag to use entropy vs baseline box comparison for box searcha
danbryce Aug 27, 2024
b086028
plot anytime performance of box search
danbryce Aug 27, 2024
62713f3
add point-based simulation
danbryce Aug 27, 2024
efd77d4
change to stratified model
danbryce Aug 28, 2024
f52c5ca
roll back base image, fix infinite interval, catch timing diff exception
danbryce Aug 29, 2024
2737bfe
Merge branch 'bug-fix-Infinity-original-width' into develop
danbryce Aug 29, 2024
7df1ad4
hand coded abstraction with bounds
danbryce Aug 31, 2024
717b031
bounds for abstractions
danbryce Sep 4, 2024
e1e5a24
fix log level inheritance, speedup odeint with sympy lambdas instead …
danbryce Sep 4, 2024
80d7588
formatting
danbryce Sep 4, 2024
e90610c
Merge branch 'develop' into aug-monthly-demo
danbryce Sep 4, 2024
62532c6
bounds write up
danbryce Sep 4, 2024
53a5f62
use odeint exclusively, and improved plotting
danbryce Sep 5, 2024
6ab8dbd
adjust odeint step
danbryce Sep 6, 2024
df8a13b
demo version
danbryce Sep 9, 2024
fecd3d4
fix cp version for gihub build
danbryce Sep 9, 2024
f2e3e08
random seed to dreal python binding, improve scipy integration
danbryce Sep 13, 2024
656c24b
support observations
danbryce Sep 13, 2024
f0c23b8
constraints on observables
danbryce Sep 13, 2024
3dc972a
adjust integration parameters to diagnose fpe
danbryce Sep 17, 2024
f2a40b9
verbose flag to get result on console
danbryce Sep 18, 2024
ca752f2
improve handling of observables in results
danbryce Sep 18, 2024
c5f41a0
format results file
danbryce Sep 18, 2024
0693e64
format
danbryce Sep 18, 2024
34c129d
Oct models
danbryce Sep 18, 2024
1cc915f
testing bug fixes
danbryce Sep 18, 2024
af6ebc7
debug models
danbryce Sep 18, 2024
8dc0ed7
Merge branch 'sep-monthly-demo' into develop
danbryce Sep 19, 2024
8bcd26c
modify demo notebook
danbryce Sep 19, 2024
b71d78c
add example of retreiving observations
danbryce Sep 19, 2024
144bdc6
clean up notebook
danbryce Sep 24, 2024
b83eeeb
clean up notebook
danbryce Sep 24, 2024
02d7897
Merge branch 'develop' into sep-monthly-demo
danbryce Sep 24, 2024
03c8dfd
setup stratification notebook
danbryce Sep 26, 2024
6751cbd
terarium models
dmosaphir Sep 27, 2024
d7d560b
draft of abstraction writeup
danbryce Sep 27, 2024
78f9955
example of SIR abstraction
danbryce Sep 30, 2024
9d3be43
ignores
danbryce Sep 30, 2024
213acaa
stratification producing meaningful result
danbryce Oct 1, 2024
ebc587e
checkpoint
danbryce Oct 2, 2024
63bb596
Merge branch 'sep-monthly-demo' of https://github.com/siftech/funman …
danbryce Oct 2, 2024
29abfb6
doc checkpoint
danbryce Oct 2, 2024
103c4d5
Merge remote-tracking branch 'origin/sep-monthly-demo' into sep-month…
danbryce Oct 2, 2024
96e8214
abstraction working, needs min/max sub in bounding
danbryce Oct 3, 2024
d08d206
Merge branch 'sep-monthly-demo' of https://github.com/siftech/funman …
danbryce Oct 3, 2024
c463c8c
complete abstraction and bounding for sirhd
danbryce Oct 4, 2024
4415747
fix stratification with probability of transition among strata
danbryce Oct 4, 2024
aacda61
fix bug with observables if not present in constraint
danbryce Oct 6, 2024
bbf56e7
configure random seed for dreal in FunmanConfig
danbryce Oct 6, 2024
e6d45bf
configure random seed for dreal in FunmanConfig
danbryce Oct 6, 2024
8fb9352
abstraction demo updates
danbryce Oct 6, 2024
a3f037c
minor fixes in examples
danbryce Oct 6, 2024
85cb5c5
minor fixes in examples
danbryce Oct 6, 2024
e21e346
Merge remote-tracking branch 'origin/sep-monthly-demo' into sep-month…
danbryce Oct 6, 2024
70422cf
complete sir for report
danbryce Oct 7, 2024
862f77a
Merge branch 'sep-monthly-demo' of https://github.com/siftech/funman …
danbryce Oct 7, 2024
9668300
setup results section
danbryce Oct 7, 2024
09ecadc
Merge remote-tracking branch 'origin/sep-monthly-demo' into sep-month…
danbryce Oct 7, 2024
56369f4
report draft
danbryce Oct 7, 2024
cbad0f2
report draft
danbryce Oct 7, 2024
8e7e6b5
rebuild doc
danbryce Oct 7, 2024
14ac68f
formatting
danbryce Oct 8, 2024
cdb03a9
support translation to bounded expression
danbryce Oct 10, 2024
af3fcb5
add stratify test case stub
danbryce Oct 10, 2024
a8560e8
move abstraction to class
danbryce Oct 11, 2024
07e9589
Merge remote-tracking branch 'origin/sep-monthly-demo' into sep-month…
danbryce Oct 11, 2024
a13a76d
distinguish file not found from file errors
danbryce Oct 11, 2024
7fff4ce
test case for abstraction from base model
danbryce Oct 11, 2024
ed42f45
Merge remote-tracking branch 'origin/sep-monthly-demo' into sep-month…
danbryce Oct 11, 2024
75614cf
test case for abstraction
danbryce Oct 11, 2024
c5b1a45
fix tests
danbryce Oct 15, 2024
f453000
remove distribution from contracted model if constant
danbryce Oct 15, 2024
66b9dfd
Merge branch 'sep-monthly-demo' into develop
danbryce Oct 15, 2024
a922f25
fix bug with null time variable
danbryce Oct 16, 2024
eb07f4b
Merge branch 'sep-monthly-demo' into develop
danbryce Oct 16, 2024
40cd843
working abstraction bounding test case
danbryce Oct 18, 2024
75f2d08
Merge branch 'develop' into sep-monthly-demo
danbryce Oct 18, 2024
7081bbd
param synth test
danbryce Oct 21, 2024
120d59f
fix bug where constraints weren't encoded for all timesteps
danbryce Oct 23, 2024
effd5f2
minor notes on abstraction WIP
danbryce Nov 1, 2024
8a1de21
abstraction and stratification
danbryce Nov 1, 2024
f089f2a
fix test
danbryce Nov 1, 2024
d9420cd
fix test
danbryce Nov 1, 2024
714528a
report draft of abstraction
danbryce Nov 4, 2024
c4e1397
Merge remote-tracking branch 'origin/sep-monthly-demo' into sep-month…
danbryce Nov 4, 2024
88daa6f
demo notebook and improvements to stratification
danbryce Nov 4, 2024
60898fa
Merge branch 'sep-monthly-demo' of https://github.com/siftech/funman …
danbryce Nov 4, 2024
6f3a10d
fix tests
danbryce Nov 4, 2024
d69d959
Merge pull request #49 from siftech/sep-monthly-demo
danbryce Nov 4, 2024
28ed1c5
bump version
danbryce Nov 4, 2024
02021bb
small bug blocking docs build
danbryce Nov 4, 2024
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ www/_static/js/badge_only.js
www/_static/js/html5shiv-printshiv.min.js
www/_static/js/html5shiv.min.js
www/_static/js/theme.js
artifacts/.DS_Store
**/.DS_Store
scratch/funman.code-workspace
**/*.gv*
./box_search.*
Expand All @@ -321,3 +321,6 @@ notebooks/saved-results/out
**/*.out
auxiliary_packages/ibex_tests/num_constraint_test
auxiliary_packages/ibex_tests/num_constraint_test.o
notes/.DS_Store
resources/amr/petrinet/monthly-demo/.DS_Store
notes/abstraction/main.synctex(busy)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Version information."""

# The following line *must* be the last in the module, exactly as formatted:
__version__ = "1.9.1"
__version__ = "1.10.0"
2 changes: 1 addition & 1 deletion auxiliary_packages/funman_demo/src/funman_demo/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Version information."""

# The following line *must* be the last in the module, exactly as formatted:
__version__ = "1.9.1"
__version__ = "1.10.0"
346 changes: 346 additions & 0 deletions auxiliary_packages/funman_demo/src/funman_demo/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,346 @@
# Helper functions to setup FUNMAN for different steps of the scenario


import json
import logging

import matplotlib.pyplot as plt
import pandas as pd

from funman import (
MODE_ODEINT,
MODE_SMT,
EncodingSchedule,
FUNMANConfig,
FunmanWorkRequest,
)
from funman.api.run import Runner
from funman.representation import Interval
from funman.representation.constraint import (
LinearConstraint,
ParameterConstraint,
StateVariableConstraint,
)
from funman.representation.parameter import Schedules
from funman.server.query import FunmanWorkRequest


def get_request(request_path):
if request_path is None:
return FunmanWorkRequest()

with open(request_path, "r") as request:
funman_request = FunmanWorkRequest.model_validate(json.load(request))
return funman_request


def get_model(model):
return (
Runner().get_model(model)
if isinstance(model, dict)
else Runner().get_model(model)
)


def set_timepoints(funman_request, timepoints):
if (
funman_request.structure_parameters is not None
and len(funman_request.structure_parameters) > 0
):
funman_request.structure_parameters[0].schedules = [
EncodingSchedule(timepoints=timepoints)
]
else:
funman_request.structure_parameters = [
Schedules(schedules=[EncodingSchedule(timepoints=timepoints)])
]


def unset_all_labels(funman_request):
if funman_request.parameters is not None:
for p in funman_request.parameters:
p.label = "any"


def set_config_options(
funman_request, debug=False, dreal_precision=1e-3, mode=MODE_SMT
):
if funman_request.config is None:
funman_request.config = FUNMANConfig()
# Overrides for configuration
#
# funman_request.config.substitute_subformulas = True
# funman_request.config.use_transition_symbols = True
# funman_request.config.use_compartmental_constraints=False
if debug:
funman_request.config.save_smtlib = "./out"
funman_request.config.tolerance = 0.01
funman_request.config.dreal_precision = dreal_precision
funman_request.config.verbosity = logging.ERROR
funman_request.config.mode = mode
funman_request.config.normalize = False
funman_request.config.random_seed = 3
# funman_request.config.dreal_log_level = "debug"
# funman_request.config.dreal_prefer_parameters = ["beta","NPI_mult","r_Sv","r_EI","r_IH_u","r_IH_v","r_HR","r_HD","r_IR_u","r_IR_v"]


def get_synthesized_vars(funman_request):
return (
[p.name for p in funman_request.parameters if p.label == "all"]
if funman_request.parameters is not None
else []
)


def run(funman_request, model, models, plot=False, SAVED_RESULTS_DIR="./out"):
to_synthesize = get_synthesized_vars(funman_request)
results = Runner().run(
models[model],
funman_request,
description="SIERHD Eval 12mo Scenario 1 q1",
case_out_dir=SAVED_RESULTS_DIR,
dump_plot=plot,
print_last_time=True,
parameters_to_plot=to_synthesize,
)
return results


def setup_common(
funman_request,
timepoints,
synthesize=False,
debug=False,
dreal_precision=1e-3,
mode=MODE_SMT,
):
set_timepoints(funman_request, timepoints)
if not synthesize:
unset_all_labels(funman_request)
set_config_options(
funman_request, debug=debug, dreal_precision=dreal_precision, mode=mode
)


def set_compartment_bounds(
funman_request, model, upper_bound=9830000.0, error=0.01
):
# Add bounds to compartments
for var in states[model]:
funman_request.constraints.append(
StateVariableConstraint(
name=f"{var}_bounds",
variable=var,
interval=Interval(
lb=0, ub=upper_bound, closed_upper_bound=True
),
soft=False,
)
)

# Add sum of compartments
funman_request.constraints.append(
LinearConstraint(
name=f"compartment_bounds",
variables=states[model],
additive_bounds=Interval(
lb=upper_bound - error,
ub=upper_bound + error,
closed_upper_bound=False,
),
soft=True,
)
)


def relax_parameter_bounds(funman_request, factor=0.1):
# Relax parameter bounds
parameters = funman_request.parameters
for p in parameters:
interval = p.interval
width = float(interval.width())
interval.lb = interval.lb - (factor / 2 * width)
interval.ub = interval.ub + (factor / 2 * width)


def plot_last_point(results, states):
pts = results.parameter_space.points()
print(f"{len(pts)} points")

if len(pts) > 0:
# Get a plot for last point
df = results.dataframe(points=pts[-1:])
# pd.options.plotting.backend = "plotly"
ax = df[states].plot()

fig = plt.figure()
# fig.set_yscale("log")
# fig.savefig("save_file_name.pdf")
plt.close()


def get_last_point_parameters(results):
pts = results.parameter_space.points()
if len(pts) > 0:
pt = pts[-1]
parameters = results.model._parameter_names()
param_values = {k: v for k, v in pt.values.items() if k in parameters}
return param_values


def pretty_print_request_params(params):
# print(json.dump(params, indent=4))
if len(params) > 0:

df = pd.DataFrame(params)
print(df.T)


def report(results, name, states, request_results, request_params):
request_results[name] = results
plot_last_point(results, states)
param_values = get_last_point_parameters(results)
# print(f"Point parameters: {param_values}")
if param_values is not None:
request_params[name] = param_values
pretty_print_request_params(request_params)


def add_unit_test(funman_request, model="sidarthe_observables"):
if model == "destratified_SEI":
mstates = states["destratified_SEI"]
funman_request.constraints.append(
LinearConstraint(
name="compartment_lb",
soft=False,
variables=[s for s in mstates if s.endswith("_lb")],
additive_bounds={"ub": 19340000.5},
)
)
funman_request.constraints.append(
LinearConstraint(
name="compartment_ub",
soft=False,
variables=[s for s in mstates if s.endswith("_ub")],
additive_bounds={"lb": 0},
)
)


def plot_bounds(
point,
results,
timespan=None,
fig=None,
axs=None,
vars=["S", "E", "I", "R", "D", "H"],
model=None,
basevar_map={},
**kwargs,
):

if point.simulation is not None:
df = point.simulation.dataframe().T
else:
df = results.dataframe([point])

if timespan is not None:
df = df.loc[timespan[0] : timespan[1]]

# print(df)

# Drop the ub vars because they are paired with the lb vars
no_ub_vars = [v for v in vars if not v.endswith("_ub")]
no_strat_vars = [v for v in no_ub_vars if not "_noncompliant" in v]

if fig is None and axs is None:
fig, axs = plt.subplots(len(basevar_map))
fig.set_figheight(3 * len(basevar_map))
fig.suptitle("Variable Bounds over time")

for var in no_strat_vars:
# print(var)
# Get index of list containing var
i = next(iter([i for i, bv in enumerate(basevar_map) if var in bv]))
# print(i)
if var.endswith("_lb"):
# var is lower bound
basevar = var.split("_lb")[0]
lb = f"{basevar}_lb"
ub = f"{basevar}_ub"
labels = [lb, ub]
elif var.endswith("_ub"):
# skip, handled as part of lb
continue
else:
# var is not of the form varname_lb
basevar = var
labels = basevar

if "_compliant" in basevar:
basevar = basevar.split("_")[0]
if isinstance(labels, list):
lb = (
df[f"{basevar}_compliant_lb"]
+ df[f"{basevar}_noncompliant_lb"]
)
ub = (
df[f"{basevar}_compliant_ub"]
+ df[f"{basevar}_noncompliant_ub"]
)
labels = [f"{basevar}_lb", f"{basevar}_ub"]
data = pd.concat([lb, ub], axis=1, keys=labels)

else:
data = (
df[f"{basevar}_compliant"] + df[f"{basevar}_noncompliant"]
)
labels = f"{basevar}"
else:
# print(labels)
data = df[labels]
if "_compliant" in basevar:
basevar = basevar.split("_")[0]
labels = f"{basevar}"

legend_labels = labels
if model is not None:
legend_labels = (
[f"{model}_{k.rsplit('_', 1)[0]}" for k in labels[0:1]][0]
if isinstance(labels, list)
else f"{model}_{labels}"
)

# Fill between lb and ub
if isinstance(labels, list):
axs[i].fill_between(
data.index,
data[labels[0]],
data[labels[1]],
label=legend_labels,
**kwargs,
)
else:
if "hatch" in kwargs:
del kwargs["hatch"]
if "alpha" in kwargs:
del kwargs["alpha"]
axs[i].plot(data, label=legend_labels, **kwargs)
axs[i].set_title(f"{basevar} Bounds")

# axs[i].set_yscale('logit')

# axs[i].legend(loc="outer")
axs[i].legend(
loc="center left",
bbox_to_anchor=(1, 0.5),
ncol=1,
fancybox=True,
shadow=True,
prop={"size": 8},
markerscale=2,
)
# ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

# fig.tight_layout()
return fig, axs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Version information."""

# The following line *must* be the last in the module, exactly as formatted:
__version__ = "1.9.1"
__version__ = "1.10.0"
Loading
Loading