Engine
- class trident.engine.Session(*, engine: EngineApi | None = None)
Bases:
objectProvides utility functions for managing a Trident session with a run of one or multiple scenarios.
- async async_run(*, wait=True)
- cancel(*, wait=True)
- check_has_engine()
- check_has_run_config()
- export_lp_files(path: str | Path)
Write all available lp reports to file.
Specify which lp files to generate in the run config. Only lp files that are generated during a run can be exported.
- get_statuses() list[RunStatus]
- init(*args, **kwargs)
Initialize the engine; sets up engine storage, and adds the specified solver modules.
If no parameters are specified, then a default configuration with persistent storage in the user data directory is initialized.
If use_disk is set to False, then a temporary in-memory storage is used.
If persistent is set to False and use_disk is not set to False, then a random directory is generated in the system’s temporary files directory.
If data_path is specified, then it will be used for the engine’s internal data files. This requires that persistent is set to True.
If solver_modules is not specified, then the default solvers to be initialized are trident.solver.coin, and if available, trident.solver.cplex.
If problem_modules is not specified, then trident_extras will be added if they are available. Note that core problem modules are available by default.
- Parameters:
num_local_workers (int) – The number of local workers to use.
persistent (bool) – Use persistent storage. Requires use_disk=True
use_disk (bool) – Store data on disk.
data_path (str) – A directory path to store trident persistent data in.
problem_modules (list) – A list of python modules to load problem modules from, or problem module factories to add.
solver_modules (list) – A list of python modules to load solver modules from, or solver modules to add.
data_service (trident.core.DataService) – An auxiliary data service to use for input data.
- property input_data: DataStore
- load_logical_model(fn: str | Path) None
- load_run_config(fn: str | Path) None
- log_validation_result(run_id: str, vres: ValidationResult)
- property logical_model: LogicalModel
- property result_data: DataProvider
- resume(*, wait=True)
- run(*, wait=True)
- save_result_files(path: str | Path)
Generate and save detsimres.h5 and SAMRES.h5.
Copy these files to the LTMv10 dataset that corresponds to the dataset run in the session. You can then run LTM applications to analyze the results.
- scenario_result_data(scenario_id: str) DataProvider
- property scenarios: dict[str, SessionScenario]
- split_scenarios()
- validate(raise_on_failure=True) ValidationResult
Runs validation, and raises an exception if validation fails. If raise_on_failure is set to False, returns a ValidationResult object.
- wait()
- class trident.engine.EngineApi
Bases:
pybind11_objectThe main interface through which applications or users should test interact with the engine. This API should provide a complete set of functions related to executing a run of Trident. (Except for engine configuration)
- __init__(*args, **kwargs)
- add_logical_model(self: EngineApi, model_id: str, logical_model: LogicalModel) None
Add a model to be stored internally. Only models stored internally can be referenced in a run config.
- add_run_config(self: EngineApi, p_run_config: RunConfig) None
Add a run configuration to be stored internally.
- get_available_modules(self: EngineApi) list[trident.domain._trident_domain.ModuleMetadata]
Get available modules
Only the modules listed here can be used during a run. If a module is missing it needs to be loaded into the engine.
- get_input_data_store(self: EngineApi, data_store_id: str) trident.core._trident_core.DataStore
Get a data store that manage data in an input data set. A new data set is created if it does not exist.
- get_logical_model(self: EngineApi, model_id: str) LogicalModel
Returns a logical model by id.
- get_logical_model_ids(self: EngineApi) list[str]
Get the ids of all logical models stored internally
- get_logical_model_source_signature(self: EngineApi, model_id: str) trident.domain._trident_domain.SourceSignature
Get the SourceSignature of a stored LogicalModel.
Two source signatures can be compared to determine whether two logical models are exactly equal.
Returns: The stored SourceSignature of that logical model, or nullptr if no corresponding logical model exists
- get_report(self: EngineApi, run_id: str, report_id: str) str
Get a report
- Valid reports:
run_summary_report: Provides a quick overview of the module, model and simulation configurations
Reports generated during a run (these need to be set in run config)
- get_report_ids(self: EngineApi, run_id: str) list[str]
Get the ids of available reports from a given run
- get_result_data_provider(self: EngineApi, run_id: str) trident.core._trident_core.DataProvider
Get a data provider that fetches data from the run results
- get_run_log(self: EngineApi, id: str) list[str]
Get a run log by the id of the run config.
Any error that occurs during a run will be retrievable here. Note that the verbosity level will influence which type of events will be logged.
- get_run_result(self: EngineApi, id: str) trident.domain._trident_domain.Result
Get the result of a run by the id of the run config.
Contains information about which result data was generated, which can be retrieved using get_result_data.
- get_run_status(self: EngineApi, id: str) trident.domain._trident_domain.RunStatus
Get a run status by the id of the run config.
Can be used to figure out whether the run is running, or if it has failed due to en error.
- get_status(self: EngineApi) trident.domain._trident_domain.Status
Get the current status of the engine.
- static get_version() str
Get the current version of Trident.
- static get_version_long() str
Get the current version of Trident, long version.
- class trident.engine.Engine
Bases:
EngineApiTrident engine - superset of
EngineApi. Used when running Trident locally, which adds increased functionality.- __init__(self: Engine, *, communicator: trident.core._trident_core.Communicator = None, num_local_workers: int = 1, use_disk: bool | None = True, persistent: bool | None = None, data_path: str | None = None, problem_modules: list[str | trident.core._trident_core.ModuleFactory | object] | None = None, solver_modules: list[str | trident.core._trident_core.SolverModule] | None = None, logger: trident.core._trident_core.Logger | object | None = None, data_service: trident.core._trident_core.DataService = None) None
Initialize the engine; sets up engine storage, and adds the specified solver modules.
If no parameters are specified, then a default configuration with persistent storage in the user data directory is initialized.
If use_disk is set to False, then a temporary in-memory storage is used.
If persistent is set to False and use_disk is not set to False, then a random directory is generated in the system’s temporary files directory.
If data_path is specified, then it will be used for the engine’s internal data files. This requires that persistent is set to True.
If solver_modules is not specified, then the default solvers to be initialized are trident.solver.coin, and if available, trident.solver.cplex.
If problem_modules is not specified, then trident_extras will be added if they are available. Note that core problem modules are available by default.
- Parameters:
num_local_workers (int) – The number of local workers to use.
persistent (bool) – Use persistent storage. Requires use_disk=True
use_disk (bool) – Store data on disk.
data_path (str) – A directory path to store trident persistent data in.
problem_modules (list) – A list of python modules to load problem modules from, or problem module factories to add.
solver_modules (list) – A list of python modules to load solver modules from, or solver modules to add.
data_service (trident.core.DataService) – An auxiliary data service to use for input data.