numerous.sdk.connect package#

Submodules#

Module contents#

numerous.sdk.connect - connect your code to the numerous platform!

The connect package contains all the functionality needed to build applications that connect to and take advantage of the numerous platform.

class numerous.sdk.connect.JobClient(channel, identity, execution_id, config=None)#

Bases: object

The 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:

JobClient

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.

Parameters:
  • hostname (str) – Hostname of the numerous server

  • port (str) – gRPC port of the numerous server

  • refresh_token (str) – Refresh token for the execution.

  • identity (JobIdentifier) – Contains identity information for the job object and related objects.

Return type:

JobClient

property group: Group | None#
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: Job#

The model of the current job.

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:

FileUploadContext

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 Project configuration, 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:

InputReader

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 reader: Reader#

Data reader for the job.

property scenario: Scenario#

The associated Scenario configuration, 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.

property status: JobStatus#

Status of the job, reported to the platform.

Getting the status returns a locally cached value.

property writer: Writer#

Data writer for the job.

class numerous.sdk.connect.JobStatus(value)#

Bases: str, Enum

An enumeration.

ERROR = 'error'#
FAILED = 'failed'#
FINISHED = 'finished'#
HIBERNATING = 'hibernating'#
INITIALIZING = 'initializing'#
RUNNING = 'running'#
STOPPED = 'stopped'#