movici_simulation_core¶
Subpackages¶
attributes¶
This module contains AttributeSpec objects
for common, generic, attribute types that can be used in datasets
csr¶
- assert_numeric_array(arr)¶
- compare_array(a, b)¶
compare function when both a and b are numpy arrays (and not float arrays)
- compare_scalar(a, b)¶
compare function for comparing an array against a scalar :param a: a numpy array :param b: a scalar
- csr_binop(data, row_ptr, operand, operator)¶
Perform binary operation
operatorrowwise on a csr array, the operand must be a 1d array of length equal to the number of rows in the csr array
- float_compare(rtol=1e-05, atol=1e-08, equal_nan=True)¶
factory function for creating a float compare function
- generate_update(data, row_ptr, mask, changed, undefined)¶
- get_new_csr_array(row_lengths, dtype, secondary_shape)¶
- get_row(data, row_ptr, index)¶
- reduce_rows(data, row_ptr, func)¶
- reduce_rows_with_substitute(data, row_ptr, func, substitute)¶
- remove_undefined_csr(data: ndarray, row_ptr: ndarray, indices: ndarray, undefined, num_undefined, new_data_shape, compare) Tuple[ndarray, ndarray, ndarray]¶
- row_wise_max(data, row_ptr, empty_row=None)¶
- row_wise_min(data, row_ptr, empty_row=None)¶
- row_wise_sum(data, row_ptr)¶
- rows_contain(data, row_ptr, val, compare)¶
- rows_equal(data, row_ptr, row, compare)¶
- rows_intersect(data, row_ptr, vals, compare)¶
- set_row(data, row_ptr, index, new_row)¶
Set a new row on at the specific index of the csr_array. WARNING: the length of the new row must be allocated in the data array, otherwise this function may override other rows
- slice_csr_array(data, row_ptr, indices)¶
- update_csr_array(data, row_ptr, upd_data, upd_row_ptr, upd_indices, compare, changes=None)¶
Update a csr array (data and row_ptr) in place with an update csr array (upd_data and upd_row_ptr at the locations upd_indices. data and upd_data must be of the same dtype and may only differ in shape in the first dimension. Can optionally track changes by changes output argument as an boolean array of zeros that has the length equal to the number of rows in of the data csr array ( len( row_ptr)-1). When tracking changes rtol, atol and equal_nan mean the same as in np.isclose
exceptions¶
- exception FSMDone¶
Bases:
FSMException
- exception FSMError¶
Bases:
FSMException
- exception FSMException¶
Bases:
Exception
- exception FSMStarted¶
Bases:
FSMException
- exception InvalidCommand¶
Bases:
OrchestratorException
- exception InvalidMessage¶
Bases:
SimulationException
- exception NotReady¶
Bases:
SimulationException
- exception OrchestratorException¶
Bases:
SimulationException
- exception SimulationException¶
Bases:
Exception
- exception StartupFailure¶
Bases:
SimulationException
- exception StreamDone¶
Bases:
SimulationException
messages¶
- class BaseUpdateMessage¶
Bases:
object- address: str | None¶
- property has_data¶
- key: str | None¶
- origin: str | None¶
- class GetDataMessage(key: 'str', mask: 't.Optional[dict]' = None)¶
Bases:
Message- key: str¶
- mask: dict | None = None¶
- class QuitMessage(due_to_failure: bool = False)¶
Bases:
MessageA message to indicate that we should stop the simulation. Allows models to gracefully terminate.
- Parameters:
due_to_failure – flag to indicate that a component has failed and that it is not a regular shutdown
- due_to_failure: bool = False¶
- class RegistrationMessage(pub: 't.Optional[dict]', sub: 't.Optional[dict]')¶
Bases:
Message- pub: dict | None¶
- sub: dict | None¶
- class ResultMessage(key: str | None = None, address: str | None = None, next_time: int | None = None, origin: str | None = None)¶
Bases:
Message,BaseUpdateMessageResponse to an UpdateMessage
- address: str | None = None¶
- key: str | None = None¶
- next_time: int | None = None¶
- origin: str | None = None¶
- class UpdateMessage(timestamp: 'int', key: 't.Optional[str]' = None, address: 't.Optional[str]' = None, origin: 't.Optional[str]' = None)¶
Bases:
Message,BaseUpdateMessage- address: str | None = None¶
- key: str | None = None¶
- origin: str | None = None¶
- timestamp: int¶
settings¶
- class Settings(_case_sensitive: bool | None = None, _nested_model_default_partial_update: bool | None = None, _env_prefix: str | None = None, _env_prefix_target: EnvPrefixTarget | None = None, _env_file: DotenvType | None = PosixPath('.'), _env_file_encoding: str | None = None, _env_ignore_empty: bool | None = None, _env_nested_delimiter: str | None = None, _env_nested_max_split: int | None = None, _env_parse_none_str: str | None = None, _env_parse_enums: bool | None = None, _cli_prog_name: str | None = None, _cli_parse_args: bool | list[str] | tuple[str, ...] | None = None, _cli_settings_source: CliSettingsSource[Any] | None = None, _cli_parse_none_str: str | None = None, _cli_hide_none_type: bool | None = None, _cli_avoid_json: bool | None = None, _cli_enforce_required: bool | None = None, _cli_use_class_docs_for_groups: bool | None = None, _cli_exit_on_error: bool | None = None, _cli_prefix: str | None = None, _cli_flag_prefix_char: str | None = None, _cli_implicit_flags: bool | Literal['dual', 'toggle'] | None = None, _cli_ignore_unknown_args: bool | None = None, _cli_kebab_case: bool | Literal['all', 'no_enums'] | None = None, _cli_shortcuts: Mapping[str, str | list[str]] | None = None, _secrets_dir: PathType | None = None, _build_sources: tuple[tuple[PydanticBaseSettingsSource, ...], dict[str, Any]] | None = None, *, data_dir: ~typing.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] = PosixPath('.'), loglevel: str = 'INFO', logformat: str = '[{asctime}] [{levelname:8s}] {name:17s}: {message}', name: str = '', storage: ~typing.Literal['api', 'file', 'sqlite'] = 'file', storage_dir: ~pathlib.Path | None = None, temp_dir: ~typing.Annotated[~pathlib.Path, ~pydantic.types.PathType(path_type=dir)] = PosixPath('/tmp'), reference: float = 0, time_scale: float = 1, start_time: int = 0, duration: int = 0, datasets: ~typing.List[dict] = <factory>, model_names: ~typing.List[str] = <factory>, models: ~typing.List[dict] = <factory>, service_types: ~typing.List[str] = <factory>, scenario_config: dict | None = None, service_discovery: ~typing.Dict[str, str] = <factory>, distributed: bool = True)¶
Bases:
BaseSettings- apply_scenario_config(config: dict)¶
- classmethod check_deprecated_storage(value: str)¶
- data_dir: DirectoryPath¶
- datasets: t.List[dict]¶
- distributed: bool¶
- duration: int¶
- log_format: str¶
- log_level: str¶
- model_config = {'arbitrary_types_allowed': True, 'case_sensitive': False, 'cli_avoid_json': False, 'cli_enforce_required': False, 'cli_exit_on_error': True, 'cli_flag_prefix_char': '-', 'cli_hide_none_type': False, 'cli_ignore_unknown_args': False, 'cli_implicit_flags': False, 'cli_kebab_case': False, 'cli_parse_args': None, 'cli_parse_none_str': None, 'cli_prefix': '', 'cli_prog_name': None, 'cli_shortcuts': None, 'cli_use_class_docs_for_groups': False, 'enable_decoding': True, 'env_file': None, 'env_file_encoding': None, 'env_ignore_empty': False, 'env_nested_delimiter': None, 'env_nested_max_split': None, 'env_parse_enums': None, 'env_parse_none_str': None, 'env_prefix': 'movici_', 'env_prefix_target': 'variable', 'extra': 'forbid', 'json_file': None, 'json_file_encoding': None, 'nested_model_default_partial_update': False, 'protected_namespaces': ('model_validate', 'model_dump', 'settings_customise_sources'), 'secrets_dir': None, 'toml_file': None, 'validate_default': True, 'yaml_config_section': None, 'yaml_file': None, 'yaml_file_encoding': None}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_names: t.List[str]¶
- models: t.List[dict]¶
- name: str¶
- reference: float¶
- scenario_config: t.Optional[dict]¶
- service_discovery: t.Dict[str, str]¶
- service_types: t.List[str]¶
- start_time: int¶
- storage: t.Literal['api', 'file', 'sqlite']¶
- storage_dir: t.Optional[Path]¶
- temp_dir: DirectoryPath¶
- time_scale: float¶
- property timeline_info¶
types¶
- class CSRAttributeData¶
Bases:
UniformAttributeData- data: ndarray¶
- ind_ptr: ndarray¶
- indptr: ndarray¶
- row_ptr: ndarray¶
- class ExternalSerializationStrategy¶
Bases:
object- with_schema(schema: AttributeSchema) ExternalSerializationStrategy¶
- class FileType(*values)¶
Bases:
Enum- CSV = ('.csv',)¶
- JSON = ('.json',)¶
- MSGPACK = ('.msgpack',)¶
- NETCDF = ('.nc',)¶
- OTHER = ('.dat',)¶
- property default_extension¶
- classmethod from_extension(ext)¶
validate¶
- class AttributeSchemaLookup(dataset_names: Sequence[str] | None = None, schema: AttributeSchema | None = None)¶
Bases:
MoviciTypeLookup- attribute(attribute_type)¶
- class FromDictLookup(datasets: List[dict] | None = None, entity_types: list | None = None, attribute_types: list | None = None, validate_dataset_types: bool = True)¶
Bases:
MoviciTypeLookup
- class ModelConfigSchema(schema: 'dict | Path', convert_from_previous: 't.Callable[[dict], dict] | None' = None)¶
Bases:
object- convert_from_previous: Callable[[dict], dict] | None = None¶
- schema: dict | Path¶
- class MoviciDataRefInfo(path: tuple[str | int, ...], value: Any, movici_type: Literal['dataset', 'entityGroup', 'attribute'] | None = None)¶
Bases:
objectA class containing information regarding a reference in a model config to a Movici object (such as a dataset, entity group or attribute). It can be to set links between a model config and the associated Movici object stored in a database. Instances of
MoviciDataRefInfoare returned byvalidate_and_process()and do generally not need to be created manually.- Parameters:
path – the path of the reference in a JSON structure as a tuple.
strvalues indicate keys in object, whileintvalues represent positions in an arrayvalue – the value of the reference
movici_type – one of
"dataset","entityGroup"or"attribute"
- classmethod from_path_string(path: str, value: Any, movici_type: Literal['dataset', 'entityGroup', 'attribute'] | None = None)¶
- property json_path¶
- movici_type: Literal['dataset', 'entityGroup', 'attribute'] | None = None¶
- path: tuple[str | int, ...]¶
- set_value(obj)¶
- unset_value(obj)¶
- value: Any¶
- class MoviciTypeLookup(datasets: Mapping[str, str | None] | None = None, entity_types: Collection[str] | None = None, attribute_types: Collection[str] | None = None)¶
Bases:
objectclass for looking up wether a specific dataset, entity_group, attribute exists or whether a dataset is of a specific type. Used alongside
validate_and_process. This class can be subclassed to provide custom logic for determining whether these objects exist- attribute(attribute_type)¶
- dataset(dataset_name)¶
- dataset_type(dataset_name, required_type)¶
- entity_group(entity_type)¶
- exception MoviciTypeReport(movici_type: Literal['dataset', 'entityGroup', 'attribute'], instance: str)¶
Bases:
ValidationErrorIndicates the existence of a
movici.typefield in the instance. By deriving fromexceptions.ValidationError, we hook into the existingjsonschemacode that sets the location of the fields. In our own code we process and drop these “errors” so that they are not raised as actual errors- asinfo()¶
- movici_type: Literal['dataset', 'entityGroup', 'attribute']¶
- anyOf(validator, anyOf, instance, schema)¶
- ensure_schema(schema_identifier: dict | str | Path, add_name_and_type=True)¶
- extract_reports(errors)¶
- get_validation_errors(config, schema)¶
- has_dataset_type(instance: str, dataset_type: str, lookup)¶
- movici_dataset_type(lookup)¶
- movici_type(lookup)¶
- movici_validator(schema, lookup: MoviciTypeLookup | None = None)¶
- oneOf(validator, oneOf, instance, schema)¶
- validate_and_migrate_config(config: dict, versions: Sequence[ModelConfigSchema], add_name_and_type=True)¶
- validate_and_process(instance: Any, schema: dict, lookup: MoviciTypeLookup | None = None, return_errors=False) tuple[list[MoviciDataRefInfo], list[ValidationError]]¶
Extension of
jsonschema.validators.validatethat strips out and processesMoviciTypeReports
- validate_movici_type(instance, movici_type, lookup)¶