numerous.sdk package#
Subpackages#
- numerous.sdk.connect package
- Submodules
- numerous.sdk.connect.access_token module
- numerous.sdk.connect.auth module
- numerous.sdk.connect.command_handler module
- numerous.sdk.connect.config module
- numerous.sdk.connect.file_manager module
- numerous.sdk.connect.hibernation module
- numerous.sdk.connect.inputs module
- numerous.sdk.connect.job_client module
- numerous.sdk.connect.job_state module
- numerous.sdk.connect.job_utils module
- numerous.sdk.connect.optimization module
- numerous.sdk.connect.reader module
- numerous.sdk.connect.request_response_stream module
- numerous.sdk.connect.status_handler module
- numerous.sdk.connect.subscription module
- numerous.sdk.connect.writer module
- Module contents
JobClientJobClient.channel_options()JobClient.close()JobClient.connect()JobClient.file_managerJobClient.flush_logs()JobClient.from_connection_params()JobClient.groupJobClient.hibernate()JobClient.jobJobClient.job_timeJobClient.logJobClient.messageJobClient.open_output_file()JobClient.parametersJobClient.progressJobClient.projectJobClient.read_inputs()JobClient.readerJobClient.scenarioJobClient.set_hibernate_callback()JobClient.set_terminate_callback()JobClient.stateJobClient.statusJobClient.writer
JobStatus
- Submodules
- numerous.sdk.models namespace
- Submodules
- numerous.sdk.models.component module
- numerous.sdk.models.group module
- numerous.sdk.models.input module
- numerous.sdk.models.job module
- numerous.sdk.models.job_time module
- numerous.sdk.models.optimization module
- numerous.sdk.models.parameter module
- numerous.sdk.models.project module
- numerous.sdk.models.scenario module
- Submodules
Submodules#
Module contents#
numerous.sdk - develop numerous applications!
The recommended way to develop applications for running on the numerous platform.
- class numerous.sdk.Component(uuid, id, type, name, item_class, is_enabled, is_main, input_variables, components, parameters, is_dummy=False)#
Bases:
objectA component of a
Scenario, containing parameters, input variables, and any subcomponents.-
components:
dict[str,list[Component]]#
- static from_document(path, component, all_components, input_sources_mapping, file_manager_client)#
- Return type:
-
id:
str#
-
input_variables:
dict[str,InputVariable]#
-
is_dummy:
bool= False# The subcomponents of this component.
-
is_enabled:
bool#
-
is_main:
bool#
-
item_class:
list[str]#
-
name:
str#
-
type:
str#
-
uuid:
str#
-
components:
- class numerous.sdk.InputVariable(uuid, id, path, display_name, source, scale=1.0, offset=0.0)#
Bases:
object-
display_name:
str#
-
id:
str#
- property key: str#
-
offset:
float= 0.0#
-
path:
list[str]#
-
scale:
float= 1.0#
-
source:
Union[InputVariableScenarioSource,InputVariableStaticSource]#
-
uuid:
str#
- property value: float | None#
-
display_name:
- class numerous.sdk.Job(id, name, is_main, parameters, time)#
Bases:
objectA job in a
numerous.sdk.models.scenario.Scenario- static from_document(job_id, data, file_manager_client, status_handler, last_hibernate_time=None)#
- Return type:
-
id:
str#
-
is_main:
bool#
-
name:
str#
- class numerous.sdk.JobClient(channel, identity, execution_id, config=None)#
Bases:
objectThe JobClient is the recommended way to connect to the numerous platform.
- static channel_options(config)#
Returns the default gRPC channel options.
- Return type:
list[tuple[str,Any]]
- close(error=None)#
Close the JobClient.
Closes the JobClient’s connection to the numerous platform, immediately terminating any active communication.
- Parameters:
error_occured¶ – If True, sets the job status with JobStatus.ERROR.
- Return type:
None
This method is idempotent.
- static connect(status=JobStatus.RUNNING, message=None)#
Create a JobClient from environment variables.
- Return type:
- Uses the following environment variables:
NUMEROUS_API_SERVER
NUMEROUS_API_PORT
NUMEROUS_API_REFRESH_TOKEN
NUMEROUS_PROJECT
NUMEROUS_SCENARIO
JOB_ID
NUMEROUS_EXECUTION_ID
- property file_manager: FileManager#
Access the file manager of the job.
- flush_logs()#
Flush all buffered log messages, so that they are sent to the server.
- Return type:
None
- static from_connection_params(hostname, port, refresh_token, identity, execution_id, config)#
Create a JobClient from connection parameters.
- hibernate()#
Hibernate the current job execution
Terminates the Python process, committing the job state to the back-end. The job can be resumed again, and the state can be reloaded to continue.
If the job is scheduled, it will then follow its schedule, and be resumed at the next scheduled resume.
- Return type:
None
- property job_time: JobTime#
The associated time setup of the job, which contains start and end times of the simulation, and the duration.
- property log: Logger#
Return the Job Client logger for the job.
- property message: str#
Status message of the job, reported to the platform. Is truncated to at most 32 characters upon setting.
Getting the status message returns a locally cached value.
- open_output_file(file_name)#
- Parameters:
file_name¶ (
str) – Output file name.- Return type:
- Returns:
An object to be used under with statement.
- Example:
>>> with JobClient.connect() as client: ... with client.open_output_file("output_data") as output_file: ... output_file.write("First file content") ... output_file.write_from_file("first_file.csv") ... output_file.write("Second file content") ... output_file.write_from_file("second_file.csv")
- property parameters: dict[str, numerous.sdk.models.parameter.Parameter]#
- property progress: float#
Progress of the job, reported to the platform. Is clamped between 0.0 and 100.0 upon setting.
Getting the progress returns a locally cached value.
- property project: Project#
The associated
Projectconfiguration, with parameters. It is a lazy property, that will load the scenario data on access.
- read_inputs(step, repeat_spacing=None, hibernating_source_action=HibernatingSourceAction.HIBERNATE_SELF, update_progress=False)#
Get an iterator over all input variables in the scenario.
This method can only be called once in the job runtime.
- Parameters:
step¶ (
float) – The distance (in time) between each read. Zero-order hold is used for values at steps that are not in the original data set.repeat_spacing¶ (
Optional[float]) – The distance (in time) between the last data point of the source data set, and the repeated first data point when repeating.
- Return type:
Returns an
InputReader, that can be iterated over.- Example:
>>> result = 0 >>> with JobClient.connect() as job_client: ... for t, data in job_client.read_inputs(step=3600.0): ... result += data["component_name.input_variable_id"]
- property scenario: Scenario#
The associated
Scenarioconfiguration, with jobs, components, parameters and input variables.It is a lazy property, that will load the scenario data on access.
- set_hibernate_callback(callback)#
Set a custom function to be called if the job is hibernated.
- Return type:
None
- set_terminate_callback(callback)#
Set a custom function to be called if the job is terminated.
- Return type:
None
- property state: JobState#
The job state, which can be persisted across hibernations.
It is a lazy property, that will load any remote state on access.
- class numerous.sdk.JobState(spm_client, identity, execution_id)#
Bases:
objectJobState enables jobs to store state remotely, and cache it locally. This is useful for keeping track of values across hibernations, or if an error has restarted the job.
- commit()#
Commit the state to the server. This is useful for batching state updates.
- Return type:
None
- set(key, value, commit=True)#
Set the state value keyed by
keyto the valuevaluein theJobState, and optionally commit the state to the server.If
commitis True the new state resulting from setting the value, will be comitted to the server.
- class numerous.sdk.JobStatus(value)#
Bases:
str,EnumAn enumeration.
- ERROR = 'error'#
- FAILED = 'failed'#
- FINISHED = 'finished'#
- HIBERNATING = 'hibernating'#
- INITIALIZING = 'initializing'#
- RUNNING = 'running'#
- STOPPED = 'stopped'#
- class numerous.sdk.JobTime(run_mode, start, end, duration, status_handler, _last_hibernate_time=None)#
Bases:
objectContains information about the job runtime.
-
current_time:
Optional[datetime] = None#
-
duration:
Optional[timedelta]#
- property elapsed: timedelta | None#
-
end:
Optional[datetime]#
- range(step=1.0, start=None, update_progress=False)#
Range over the runtime of the job, from
starttoend, inclusive. Ifendis not defined, range forever. If the job is resumed from hibernation, the start time will be the job time before hibernation.
-
start:
datetime#
- start_to_time(t)#
- Return type:
timedelta
-
status_handler:
StatusHandler#
-
current_time:
- class numerous.sdk.Parameter(id, uuid, display_name, type, value)#
Bases:
object-
display_name:
str#
-
id:
str#
-
type:
str#
-
uuid:
str#
-
value:
Any#
-
display_name:
- class numerous.sdk.RunMode(value)#
Bases:
EnumAn enumeration.
- CONTINUOUS = 'continuous'#
- DURATION = 'duration'#
- class numerous.sdk.Scenario(id, name, components, parameters, jobs, input_sources, input_variables, group_id, optimization=None)#
Bases:
object- static from_document(data, file_manager_client, status_handler, optimization=None, last_hibernate_time=None)#
- Return type:
-
group_id:
str#
-
id:
str#
-
input_sources:
list[InputSource]#
-
input_variables:
list[InputVariable]#
-
name:
str#
-
optimization:
Optional[OptimizationConfiguration] = None#