atomica.project.Project¶
- class atomica.project.Project(name='default', framework=None, databook=None, do_run=True, sim_start=None, sim_end=None, sim_dt=None)[source]¶
Bases:
NamedItem
Main simulation container
A Project provides a centralized point of storage when working with Atomica. It contains
A framework
Data
Parameters
Programs
Scenarios and optimizations
Results
Importantly, it is generally assumed that saving and loading work is done by saving and loading projects.
- Parameters:
name
framework – a Framework to use. This could be - A filename to an Excel file on disk - An sc.Spreadsheet instance - A ProjectFramework instance - None (this should generally not be used though!)
databook – The path to a databook file. The databook will be loaded into Project.data and the spreadsheet saved to Project.databook
do_run (
bool
) – If True, a simulation will be run upon project constructionsim_start (
float
) – Optionally specify the sim start year (otherwise will default to the first year in the databook)sim_end (
float
) – Optionally specify simulation end yearsim_dt (
float
) – Optionally specify simulation timestep
NamedItem constructor
A name must be a string
- Parameters:
name
Attributes
Dictionary of
ParameterSet
instancesMethods
Method to perform automatic calibration.
copy
Generate an empty data-input Excel spreadsheet corresponding to the framework of this project.
Load binary project file
Load a data spreadsheet
Create a ProgramSet given a progbook
Transform project data into a set of parameters that can be used in model simulations.
Save a blank program book
Make new scenario and store in Project
Shortcut for getting an optimization
Shortcut for getting a parset
plot
Shortcut for getting a progset
Shortcut for getting an result -- a little special since they don't have a fixed type
Run an optimization
Run sampled simulations
Run all active scenarios
Run a single simulation
Save binary project file
Shortcut for getting a scenario
Modify the project settings, e.g. the simulation time vector.
- calibrate(parset=None, adjustables=None, measurables=None, max_time=60, save_to_project=False, new_name=None, default_min_scale=0.0, default_max_scale=2.0, default_weight=1.0, default_metric='fractional', **kwargs)[source]¶
Method to perform automatic calibration.
- Return type:
- The adjustables argument should be a list in the form of…
[par_name_1, par_name_2, charac_name_1]
- …or…
- [(par_name_1, pop_1, min_scale_1, max_scale_1)
(par_name_2, None, min_scale_2, max_scale_2), (charac_name_1, pop_2, min_scale_3, max_scale_3)]
The former instructs specified parameter values for all populations to be varied between default scaling limits. The latter varies specified parameters for specified populations, within specified scaling limits. ‘None’ in the population position represents independent scaling across all populations.
- The measurables argument should be a list in the form of…
[charac_name_1, charac_name_2]
- …or…
- [(charac_name_1, pop_1, weight_1, “fractional”)
(charac_name_2, None, weight_2, “wape”)]
The former calculates a ‘fractional’ data comparison metric across specified characteristics for all pops. The latter calculates its metric for specified populations and for both specified weights and metric types. ‘None’ represents combining the metric across all populations.
To calibrate a project-attached parameter set in place, provide its key as the new name argument to this method. Current fitting metrics are: “fractional”, “meansquare”, “wape” Note that scaling limits are absolute, not relative.
- create_databook(databook_path=None, num_pops=1, num_transfers=0, data_start=2000.0, data_end=2020.0, data_dt=1.0)[source]¶
Generate an empty data-input Excel spreadsheet corresponding to the framework of this project.
- static load(filepath)[source]¶
Load binary project file
This method is an alternate constructor that is used to load a binary file saved using
Project.save()
. Migration is automatically performed as part of the loading operation.- Parameters:
filepath – The file path/name to load
- Returns:
A new
Project
instance
- load_databook(databook_path, make_default_parset=True, do_run=True)[source]¶
Load a data spreadsheet
- Parameters:
databook_path – Databook input. Supported inputs are: - A path string, which will load a file from disk - An sc.Spreadsheet containing the contents of a databook - A ProjectData instance
make_default_parset (
bool
) – If True, a Parset called “default” will be immediately created from the newly-added datado_run (
bool
) – If True, a simulation will be run using the new parset
- Return type:
- load_progbook(progbook_path=None, name='default')[source]¶
Create a ProgramSet given a progbook
- Parameters:
progbook_path – Path to a program spreadsheet or an AtomicaSpreadsheet instance
name – The name to assign to the new ProgramSet
- Returns:
The newly created ProgramSet (also stored in
self.progsets
)
- make_parset(name='default')[source]¶
Transform project data into a set of parameters that can be used in model simulations.
- make_progbook(progbook_path=None, progs=None, data_start=None, data_end=None)[source]¶
Save a blank program book
This method will create a temporary
ProgramSet
and save it to the requested path
- parsets¶
Dictionary of
ParameterSet
instances
- result(key=None, verbose=2)[source]¶
Shortcut for getting an result – a little special since they don’t have a fixed type
- run_optimization(optimname=None, maxtime=None, maxiters=None, store_results=True)[source]¶
Run an optimization
- run_sampled_sims(parset, progset=None, progset_instructions=None, result_names=None, n_samples=1, parallel=False, max_attempts=None, num_workers=None)[source]¶
Run sampled simulations
This method samples from the parset (and progset if provided). It is separate from run_sim for several reasons
To avoid inadvertantly blowing up the size of the project, run_sampled_sims does not support automatic result saving
run_sim always returns a Result - if rolled into one function, the return type would not be predictable
- run_sim only takes in a single
ProgramInstructions
andresult_name
whereas run_sampled_sims supports iteration over multiple instructions
- run_sim only takes in a single
The other common scenario is having multiple results
- Parameters:
n_samples (
int
) – An integer number of samplesparset – A
ParameterSet
instanceprogset – Optionally a
ProgramSet
instanceprogset_instructions – This can be a list of instructions
result_names – Optionally specify names for each result. The most common usage would be when passing in a list of program instructions corresponding to different budget scenarios. The result names should be a list the same length as the instructions, or containing a single element if not using programs.
parallel – If True, run simulations in parallel (on Windows, must have
if __name__ == '__main__'
gating the calling code)max_attempts – Number of retry attempts for bad initializations
num_workers – If
parallel
is True, this determines the number of parallel workers to use (default is usually number of CPUs)
- Return type:
- Returns:
A list of Results that can be passed to Ensemble.update(). If multiple instructions are provided, the return value of this function will be a list of lists, where the inner list iterates over different instructions for the same parset/progset samples. It is expected in that case that the Ensemble’s mapping function would take in a list of results
- run_sim(parset=None, progset=None, progset_instructions=None, store_results=False, result_name=None)[source]¶
Run a single simulation
This function is the main entry point for running model simulations, given a parset and optionally program set + instructions.
- Parameters:
parset – A
ParameterSet
instance, or the name of a parset contained inself.parsets
. IfNone
, then the most recently added parset will be used (the last entry inself.parsets
)progset – Optionally pass in a
ProgramSet
instance, or the name of a progset contained inself.progsets
progset_instructions – A
ProgramInstructions
instance. Programs will only be used if a instructions are providedstore_results – If True, then the result will automatically be stored in
self.results
result_name (
str
) – Optionally assign a specific name to the result (otherwise, a unique default name will automatically be selected)
- Returns:
A
Result
instance