Run Module¶
This section documents the run components of the Nextmv Python SDK.
run
¶
This module contains definitions for an app run.
CLASS | DESCRIPTION |
---|---|
Metadata |
Metadata of a run, whether it was successful or not. |
RunInformation |
Information of a run. |
ErrorLog |
Error log of a run, when it was not successful. |
RunResult |
Result of a run, whether it was successful or not. |
RunLog |
Log of a run. |
FormatInput |
Input format for a run configuration. |
FormatOutput |
Output format for a run configuration. |
Format |
Format for a run configuration. |
RunType |
The actual type of the run. |
RunTypeConfiguration |
Defines the configuration for the type of the run that is being executed on an application. |
RunQueuing |
RunQueuing configuration for a run. |
RunConfiguration |
Configuration for an app run. |
ExternalRunResult |
Result of a run used to configure a new application run as an external one. |
TrackedRunStatus |
The status of a tracked run. |
TrackedRun |
An external run that is tracked in the Nextmv platform. |
FUNCTION | DESCRIPTION |
---|---|
run_duration |
Calculate the duration of a run in milliseconds. |
ErrorLog
¶
Bases: BaseModel
Error log of a run, when it was not successful.
You can import the ErrorLog
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Error message. Defaults to None.
TYPE:
|
|
Standard output. Defaults to None.
TYPE:
|
|
Standard error. Defaults to None.
TYPE:
|
ExternalRunResult
¶
Bases: BaseModel
Result of a run used to configure a new application run as an external one.
You can import the ExternalRunResult
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
ID of the output upload. Defaults to None.
TYPE:
|
|
ID of the error upload. Defaults to None.
TYPE:
|
|
Status of the run. Must be "succeeded" or "failed". Defaults to None.
TYPE:
|
|
Error message of the run. Defaults to None.
TYPE:
|
|
Duration of the run, in milliseconds. Defaults to None.
TYPE:
|
Examples:
>>> from nextmv import ExternalRunResult
>>> # Successful external run
>>> result = ExternalRunResult(
... output_upload_id="upload-12345",
... status="succeeded",
... execution_duration=5000
... )
>>> result.status
'succeeded'
>>> result.execution_duration
5000
>>> # Failed external run
>>> failed_result = ExternalRunResult(
... error_upload_id="error-67890",
... status="failed",
... error_message="Optimization failed due to invalid constraints",
... execution_duration=2000
... )
>>> failed_result.status
'failed'
>>> failed_result.error_message
'Optimization failed due to invalid constraints'
error_message
class-attribute
instance-attribute
¶
Error message of the run.
error_upload_id
class-attribute
instance-attribute
¶
ID of the error upload.
execution_duration
class-attribute
instance-attribute
¶
Duration of the run, in milliseconds.
output_upload_id
class-attribute
instance-attribute
¶
ID of the output upload.
Format
¶
Bases: BaseModel
Format for a run configuration.
You can import the Format
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Input format for the run configuration.
TYPE:
|
|
Output format for the run configuration. Defaults to None.
TYPE:
|
Examples:
>>> from nextmv import Format, FormatInput, FormatOutput, InputFormat, OutputFormat
>>> format_config = Format(
... format_input=FormatInput(input_type=InputFormat.JSON),
... format_output=FormatOutput(output_type=OutputFormat.JSON)
... )
>>> format_config.format_input.input_type
<InputFormat.JSON: 'json'>
>>> format_config.format_output.output_type
<OutputFormat.JSON: 'json'>
format_input
class-attribute
instance-attribute
¶
format_input: FormatInput = Field(
serialization_alias="input",
validation_alias=AliasChoices("input", "format_input"),
)
Input format for the run configuration.
format_output
class-attribute
instance-attribute
¶
format_output: Optional[FormatOutput] = Field(
serialization_alias="output",
validation_alias=AliasChoices(
"output", "format_output"
),
default=None,
)
Output format for the run configuration.
FormatInput
¶
Bases: BaseModel
Input format for a run configuration.
You can import the FormatInput
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Type of the input format. Defaults to
TYPE:
|
Examples:
>>> from nextmv import FormatInput, InputFormat
>>> format_input = FormatInput()
>>> format_input.input_type
<InputFormat.JSON: 'json'>
>>> format_input = FormatInput(input_type=InputFormat.TEXT)
>>> format_input.input_type
<InputFormat.TEXT: 'text'>
input_type
class-attribute
instance-attribute
¶
input_type: InputFormat = Field(
serialization_alias="type",
validation_alias=AliasChoices("type", "input_type"),
default=JSON,
)
Type of the input format.
FormatOutput
¶
Bases: BaseModel
Output format for a run configuration.
You can import the FormatOutput
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Type of the output format. Defaults to
TYPE:
|
Examples:
>>> from nextmv import FormatOutput, OutputFormat
>>> format_output = FormatOutput()
>>> format_output.output_type
<OutputFormat.JSON: 'json'>
>>> format_output = FormatOutput(output_type=OutputFormat.CSV_ARCHIVE)
>>> format_output.output_type
<OutputFormat.CSV_ARCHIVE: 'csv_archive'>
output_type
class-attribute
instance-attribute
¶
output_type: OutputFormat = Field(
serialization_alias="type",
validation_alias=AliasChoices("type", "output_type"),
default=JSON,
)
Type of the output format.
Metadata
¶
Bases: BaseModel
Metadata of a run, whether it was successful or not.
You can import the Metadata
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
ID of the application where the run was submitted to.
TYPE:
|
|
ID of the instance where the run was submitted to.
TYPE:
|
|
ID of the version of the application where the run was submitted to.
TYPE:
|
|
Date and time when the run was created.
TYPE:
|
|
Duration of the run in milliseconds.
TYPE:
|
|
Error message if the run failed.
TYPE:
|
|
Size of the input in bytes.
TYPE:
|
|
Size of the output in bytes.
TYPE:
|
|
Format of the input and output of the run.
TYPE:
|
|
Deprecated: use status_v2.
TYPE:
|
|
Status of the run.
TYPE:
|
application_id
instance-attribute
¶
ID of the application where the run was submitted to.
application_instance_id
instance-attribute
¶
ID of the instance where the run was submitted to.
application_version_id
instance-attribute
¶
ID of the version of the application where the run was submitted to.
status
class-attribute
instance-attribute
¶
Deprecated: use status_v2.
RunConfiguration
¶
Bases: BaseModel
Configuration for an app run.
You can import the RunConfiguration
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Execution class for the instance. Defaults to None.
TYPE:
|
|
Format for the run configuration. Defaults to None.
TYPE:
|
|
Run type configuration for the run. Defaults to None.
TYPE:
|
|
ID of the secrets collection to use for the run. Defaults to None.
TYPE:
|
|
Queuing configuration for the run. Defaults to None.
TYPE:
|
Examples:
>>> from nextmv import RunConfiguration, RunQueuing
>>> config = RunConfiguration(
... execution_class="large",
... queuing=RunQueuing(priority=1)
... )
>>> config.execution_class
'large'
>>> config.queuing.priority
1
>>> # Basic configuration
>>> basic_config = RunConfiguration()
>>> basic_config.format is None
True
execution_class
class-attribute
instance-attribute
¶
Execution class for the instance.
format
class-attribute
instance-attribute
¶
format: Optional[Format] = None
Format for the run configuration.
queuing
class-attribute
instance-attribute
¶
queuing: Optional[RunQueuing] = None
Queuing configuration for the run.
resolve
¶
resolve(
input: Union[Input, dict[str, Any], BaseModel, str],
dir_path: Optional[str] = None,
) -> None
Resolves the run configuration by modifying or setting the format
,
based on the type of input that is provided.
PARAMETER | DESCRIPTION |
---|---|
|
The input to use for resolving the run configuration.
TYPE:
|
|
The directory path where inputs can be loaded from.
TYPE:
|
Examples:
>>> from nextmv import RunConfiguration
>>> config = RunConfiguration()
>>> config.resolve({"key": "value"})
>>> config.format.format_input.input_type
<InputFormat.JSON: 'json'>
>>> config = RunConfiguration()
>>> config.resolve("text input")
>>> config.format.format_input.input_type
<InputFormat.TEXT: 'text'>
>>> config = RunConfiguration()
>>> config.resolve({}, dir_path="/path/to/files")
>>> config.format.format_input.input_type
<InputFormat.MULTI_FILE: 'multi_file'>
Source code in nextmv/nextmv/run.py
run_type
class-attribute
instance-attribute
¶
run_type: Optional[RunTypeConfiguration] = None
Run type configuration for the run.
secrets_collection_id
class-attribute
instance-attribute
¶
ID of the secrets collection to use for the run.
RunInformation
¶
Bases: BaseModel
Information of a run.
You can import the RunInformation
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Description of the run.
TYPE:
|
|
ID of the run.
TYPE:
|
|
Metadata of the run.
TYPE:
|
|
Name of the run.
TYPE:
|
|
Email of the user who submitted the run.
TYPE:
|
|
URL to the run in the Nextmv console. Defaults to "".
TYPE:
|
console_url
class-attribute
instance-attribute
¶
URL to the run in the Nextmv console.
synced_at
class-attribute
instance-attribute
¶
Timestamp when the run was synced with the remote run. This field is
None if the run was not created using Application.sync
or if the run
has not been synced yet.
synced_run_id
class-attribute
instance-attribute
¶
ID of the synced remote run, if applicable. When the Application.sync
method is used, this field marks the association between the local run
(id
) and the remote run (synced_run_id
). This field is None if the run
was not created using Application.sync
or if the run has not been synced
yet.
RunLog
¶
Bases: BaseModel
Log of a run.
You can import the RunLog
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Log of the run.
TYPE:
|
Examples:
>>> from nextmv import RunLog
>>> run_log = RunLog(log="Optimization completed successfully")
>>> run_log.log
'Optimization completed successfully'
>>> # Multi-line log
>>> multi_line_log = RunLog(log="Starting optimization\nProcessing data\nCompleted")
>>> multi_line_log.log
'Starting optimization\nProcessing data\nCompleted'
RunQueuing
¶
Bases: BaseModel
RunQueuing configuration for a run.
You can import the RunQueuing
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Priority of the run in the queue. 1 is the highest priority, 9 is the lowest priority. Defaults to None.
TYPE:
|
|
Whether the run should be queued, or not. If True, the run will not be queued. If False, the run will be queued. Defaults to None.
TYPE:
|
Examples:
>>> from nextmv import RunQueuing
>>> queuing = RunQueuing(priority=1, disabled=False)
>>> queuing.priority
1
>>> queuing.disabled
False
RunResult
¶
Bases: RunInformation
Result of a run, whether it was successful or not.
You can import the RunResult
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Error log of the run. Only available if the run failed. Defaults to None.
TYPE:
|
|
Output of the run. Only available if the run succeeded. Defaults to None.
TYPE:
|
console_url
class-attribute
instance-attribute
¶
URL to the run in the Nextmv console.
error_log
class-attribute
instance-attribute
¶
error_log: Optional[ErrorLog] = None
Error log of the run. Only available if the run failed.
output
class-attribute
instance-attribute
¶
Output of the run. Only available if the run succeeded.
synced_at
class-attribute
instance-attribute
¶
Timestamp when the run was synced with the remote run. This field is
None if the run was not created using Application.sync
or if the run
has not been synced yet.
synced_run_id
class-attribute
instance-attribute
¶
ID of the synced remote run, if applicable. When the Application.sync
method is used, this field marks the association between the local run
(id
) and the remote run (synced_run_id
). This field is None if the run
was not created using Application.sync
or if the run has not been synced
yet.
RunType
¶
Bases: str
, Enum
The actual type of the run.
You can import the RunType
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Standard run type.
TYPE:
|
|
External run type.
TYPE:
|
|
Ensemble run type.
TYPE:
|
Examples:
>>> from nextmv import RunType
>>> run_type = RunType.STANDARD
>>> run_type
<RunType.STANDARD: 'standard'>
>>> run_type.value
'standard'
>>> # Creating from string
>>> external_type = RunType("external")
>>> external_type
<RunType.EXTERNAL: 'external'>
RunTypeConfiguration
¶
Bases: BaseModel
Defines the configuration for the type of the run that is being executed on an application.
You can import the RunTypeConfiguration
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
Type of the run.
TYPE:
|
|
ID of the definition for the run type. Defaults to None.
TYPE:
|
|
ID of the reference for the run type. Defaults to None.
TYPE:
|
Examples:
>>> from nextmv import RunTypeConfiguration, RunType
>>> config = RunTypeConfiguration(run_type=RunType.STANDARD)
>>> config.run_type
<RunType.STANDARD: 'standard'>
>>> config.definition_id is None
True
>>> # External run with reference
>>> external_config = RunTypeConfiguration(
... run_type=RunType.EXTERNAL,
... reference_id="ref-12345"
... )
>>> external_config.run_type
<RunType.EXTERNAL: 'external'>
>>> external_config.reference_id
'ref-12345'
>>> # Ensemble run with definition
>>> ensemble_config = RunTypeConfiguration(
... run_type=RunType.ENSEMBLE,
... definition_id="def-67890"
... )
>>> ensemble_config.run_type
<RunType.ENSEMBLE: 'ensemble'>
>>> ensemble_config.definition_id
'def-67890'
TrackedRun
dataclass
¶
TrackedRun(
status: TrackedRunStatus,
input: Optional[
Union[Input, dict[str, Any], str]
] = None,
output: Optional[
Union[Output, dict[str, Any], str]
] = None,
duration: Optional[int] = None,
error: Optional[str] = None,
logs: Optional[list[str]] = None,
name: Optional[str] = None,
description: Optional[str] = None,
input_dir_path: Optional[str] = None,
output_dir_path: Optional[str] = None,
)
An external run that is tracked in the Nextmv platform.
You can import the TrackedRun
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
The status of the run being tracked. This field is required.
TYPE:
|
|
The input of the run being tracked. Please note that if the input
format is JSON, then the input data must be JSON serializable. If both
TYPE:
|
|
The output of the run being tracked. Please note that if the output
format is JSON, then the output data must be JSON serializable. If both
TYPE:
|
|
The duration of the run being tracked, in milliseconds. This field is optional. Defaults to None.
TYPE:
|
|
An error message if the run failed. You should only specify this if the
run failed (the
TYPE:
|
|
The logs of the run being tracked. Each element of the list is a line in the log. This field is optional. Defaults to None.
TYPE:
|
|
Optional name for the run being tracked. Defaults to None.
TYPE:
|
|
Optional description for the run being tracked. Defaults to None.
TYPE:
|
|
Path to a directory containing input files. If specified, the calling
function will package the files in the directory into a tar file and upload
it as a large input. This is useful for non-JSON input formats, such as
when working with
TYPE:
|
|
Path to a directory containing output files. If specified, the calling
function will package the files in the directory into a tar file and upload
it as a large output. This is useful for non-JSON output formats, such as
when working with
TYPE:
|
Examples:
>>> from nextmv import TrackedRun, TrackedRunStatus
>>> # Successful run
>>> run = TrackedRun(
... status=TrackedRunStatus.SUCCEEDED,
... input={"vehicles": 5, "locations": 10},
... output={"routes": [{"stops": [1, 2, 3]}]},
... duration=5000,
... name="test-run",
... description="A test optimization run"
... )
>>> run.status
<TrackedRunStatus.SUCCEEDED: 'succeeded'>
>>> run.duration
5000
>>> # Failed run with error
>>> failed_run = TrackedRun(
... status=TrackedRunStatus.FAILED,
... input={"vehicles": 0},
... error="No vehicles available for routing",
... duration=1000,
... logs=["Starting optimization", "Error: No vehicles found"]
... )
>>> failed_run.status
<TrackedRunStatus.FAILED: 'failed'>
>>> failed_run.error
'No vehicles available for routing'
>>> # Run with directory-based input/output
>>> dir_run = TrackedRun(
... status=TrackedRunStatus.SUCCEEDED,
... input_dir_path="/path/to/input/files",
... output_dir_path="/path/to/output/files",
... duration=10000
... )
>>> dir_run.input_dir_path
'/path/to/input/files'
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the status value is invalid, if an error message is provided for a successful run, or if input/output formats are not JSON or input/output dicts are not JSON serializable. |
description
class-attribute
instance-attribute
¶
Optional description for the run being tracked.
duration
class-attribute
instance-attribute
¶
The duration of the run being tracked, in milliseconds.
error
class-attribute
instance-attribute
¶
An error message if the run failed. You should only specify this if the run failed, otherwise an exception will be raised.
input
class-attribute
instance-attribute
¶
The input of the run being tracked. Please note that if the input
format is JSON, then the input data must be JSON serializable. If both
input
and input_dir_path
are specified, the input
is ignored, and
the files in the directory are used instead.
input_dir_path
class-attribute
instance-attribute
¶
Path to a directory containing input files. If specified, the calling
function will package the files in the directory into a tar file and upload
it as a large input. This is useful for non-JSON input formats, such as
when working with CSV_ARCHIVE
or MULTI_FILE
. If both input
and
input_dir_path
are specified, the input
is ignored, and the files in
the directory are used instead.
logs
class-attribute
instance-attribute
¶
The logs of the run being tracked. Each element of the list is a line in the log.
logs_text
¶
Returns the logs as a single string.
Each log entry is separated by a newline character.
RETURNS | DESCRIPTION |
---|---|
str
|
The logs as a single string. If no logs are present, an empty string is returned. |
Examples:
>>> from nextmv import TrackedRun, TrackedRunStatus
>>> run = TrackedRun(
... status=TrackedRunStatus.SUCCEEDED,
... logs=["Starting optimization", "Processing data", "Optimization complete"]
... )
>>> run.logs_text()
'Starting optimization\nProcessing data\nOptimization complete'
>>> # Single string log
>>> run_with_string_log = TrackedRun(
... status=TrackedRunStatus.SUCCEEDED,
... logs="Single log entry"
... )
>>> run_with_string_log.logs_text()
'Single log entry'
>>> # No logs
>>> run_no_logs = TrackedRun(status=TrackedRunStatus.SUCCEEDED)
>>> run_no_logs.logs_text()
''
RAISES | DESCRIPTION |
---|---|
TypeError
|
If |
Source code in nextmv/nextmv/run.py
name
class-attribute
instance-attribute
¶
Optional name for the run being tracked.
output
class-attribute
instance-attribute
¶
The output of the run being tracked. Please note that if the output
format is JSON, then the output data must be JSON serializable. If both
output
and output_dir_path
are specified, the output
is ignored, and
the files in the directory are used instead.
output_dir_path
class-attribute
instance-attribute
¶
Path to a directory containing output files. If specified, the calling
function will package the files in the directory into a tar file and upload
it as a large output. This is useful for non-JSON output formats, such as
when working with CSV_ARCHIVE
or MULTI_FILE
. If both output
and
output_dir_path
are specified, the output
is ignored, and the files
are saved in the directory instead.
TrackedRunStatus
¶
Bases: str
, Enum
The status of a tracked run.
You can import the TrackedRunStatus
class directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
The run succeeded.
TYPE:
|
|
The run failed.
TYPE:
|
Examples:
>>> from nextmv import TrackedRunStatus
>>> status = TrackedRunStatus.SUCCEEDED
>>> status
<TrackedRunStatus.SUCCEEDED: 'succeeded'>
>>> status.value
'succeeded'
>>> # Creating from string
>>> failed_status = TrackedRunStatus("failed")
>>> failed_status
<TrackedRunStatus.FAILED: 'failed'>
run_duration
¶
Calculate the duration of a run in milliseconds.
You can import the run_duration
function directly from nextmv
:
PARAMETER | DESCRIPTION |
---|---|
|
The start time of the run. Can be a datetime object or a float representing the start time in seconds since the epoch.
TYPE:
|
|
The end time of the run. Can be a datetime object or a float representing the end time in seconds since the epoch.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The duration of the run in milliseconds. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the start time is after the end time. |
TypeError
|
If start and end are not both datetime objects or both float numbers. |
Examples:
>>> from datetime import datetime, timedelta
>>> start_dt = datetime(2023, 1, 1, 12, 0, 0)
>>> end_dt = datetime(2023, 1, 1, 12, 0, 1)
>>> run_duration(start_dt, end_dt)
1000
>>> start_float = 1672574400.0 # Corresponds to 2023-01-01 12:00:00
>>> end_float = 1672574401.0 # Corresponds to 2023-01-01 12:00:01
>>> run_duration(start_float, end_float)
1000