Skip to content

SolveJob

A SolveJob represents a job for solving an optimization problem using LunaSolve. For more details, visit the API Reference.


Get Status of a SolveJob

You can retrieve the status of a SolveJob with:

solve_job.get_status()

By specifying the status_source with remote you enforce retrieving the status from the LunaPlatform.

solve_job.get_status(status_source='remote')

The default behavior is cached and uses the status retrieved from the cached status.

Get the Results of a SolveJob

Retrieve the results of the SolveJob from Luna with:

result = solve_job.result()

This will wait until the result is available. You can specify a timeout.

Refer to Solution how to evaluate the result object.

Cancel a SolveJob

You can cancel a SolveJob as long as it hasn't started yet. To cancel a SolveJob use:

solve_job.cancel()

Deleting a SolveJob

If you no longer need the SolveJob including its results, then you can delete it with:

solve_job.delete()

Hint

Delete finished SolveJobs. Use the cancel method to cancel the execution of the SolveJob.


API Reference

SolveJob

Bases: BaseModel

A model to represent a job for solving model problems.

error_message class-attribute instance-attribute

error_message: str | None = None

id instance-attribute

id: str

is_cancelable class-attribute instance-attribute

is_cancelable: bool = True

is_cancellation_requested class-attribute instance-attribute

is_cancellation_requested: bool = False

provider class-attribute instance-attribute

provider: str | None = None

solver_job_info class-attribute instance-attribute

solver_job_info: str | None = None

status instance-attribute

status: StatusEnum

status_timeline instance-attribute

status_timeline: dict[StatusEnum, datetime]

used_format class-attribute instance-attribute

used_format: ModelFormat | None = None

cancel

cancel(client: ILunaSolve | None = None) -> None

Cancel a solve job.

This method cancels an already initiated solve job using the provided client or a default one if no client is specified.

Parameters:

Name Type Description Default
client Optional[ILunaSolve]

The client instance used to perform the cancel operation. If None, the client is obtained via the ClientFactory.

None

Returns:

Type Description
None

delete

delete(client: ILunaSolve | None = None) -> None

Delete a job using the specified or default client.

This method deletes this job and solution. A client can optionally be provided otherwise, a default client is obtained through the factory.

Parameters:

Name Type Description Default
client Optional[ILunaSolve]

The client to be used for job deletion. If not provided, a default client is retrieved using ClientFactory.

None

get_status

get_status(
    client: ILunaSolve | None = None,
    status_source: Literal["cached", "remote"] = "cached",
) -> StatusEnum

Retrieve the current status of the solve job.

Parameters:

Name Type Description Default
status_source Literal['cached', 'remote']

If "cached", the status is retrieved from the cached status. If "remote", the status is retrieved from the remote service.

'cached'
client Optional[ILunaSolve]

The client to be used. If not provided, a new client is created using

None

Returns:

Type Description
StatusEnum

The current status of the solve job, represented as a value from the StatusEnum enumeration.

result

result(
    client: ILunaSolve | None = None,
    sleep_time_max: float = 60.0,
    sleep_time_increment: float = 5.0,
    sleep_time_initial: float = 5.0,
    call_style: CallStyle = ACTIVE_WAITING,
) -> Solution | None

Get the result of the solve job.

This function uses the provided client or creates a new one to retrieve and the result of this solve job. Depending on the call style, it can actively wait for the result or return immediately.

Parameters:

Name Type Description Default
client Optional[ILunaSolve]

The client to be used. If not provided, a new client is created using ClientFactory.

None
sleep_time_max float

Maximum sleep time in seconds between consecutive active waiting checks.

60.0
sleep_time_increment float

Increment value for the sleep time between checks during active waiting.

5.0
sleep_time_initial float

Initial sleep time in seconds for the active waiting process.

5.0
call_style CallStyle

Determines if this function will actively wait for the result or return immediately.

ACTIVE_WAITING

Returns:

Type Description
Optional[Solution]

The result of the solve job or None if not available.

Raises:

Type Description
Any exceptions raised by the use case's solve job call will propagate.

set_evaluation_model

set_evaluation_model(model: Model | None) -> None

Set the evaluation model for the solved job.

This will be done automatically. Normally there is no need to call this method.

Parameters:

Name Type Description Default
model Model | None
required