Skip to main content

Jobs

When solving an Optimization Model, an Optimization Job is generated that spawns a Sub Job that runs on your selected solver.

These jobs can be accessed via the main Jobs page or directly on the Resource page. Each job provides details about its execution, including any associated files or data generated. Visualizations for various data types are available, with new ones frequently added.

The Optimization Job aggregates the results of the Sub Jobs and provides the best solution found. The Sub Job is a single execution of the solver on a specific model configuration and will contain product specific execution data and specific error logs.

Running a Job

The StrangeworksOptimizer class employs the run() method to initiate a job. This method requires model, solver, and options as arguments.

optimizer = StrangeworksOptimizer(model=model, solver=solver, options=options)
sw_job = optimizer.run()

Status

Job progress can be monitored on the portal or through the SDK like so:

print(f"Job status: {optimizer.status(sw_job.slug)}")

The statuses include:

  • QUEUED: The job is queued for execution.
  • CANCELLED: On some systems it is possible to cancel jobs
  • RUNNING: The job is currently being processed.
  • COMPLETED: The job has finished, and results are available.
  • FAILED: The job encountered an error during execution.

💡 Failed Jobs:

If the job status comes back as failed you can view the job page in the portal or use the Strangeworks SDK to retrieve the errors:

import strangeworks as sw

sw.get_error_messages(sw_job.slug)

Results

Once a job is completed, you can fetch the solution.

results = optimizer.results(sw_job.slug)
print(f"Best solution:\n{results.solution.first}")

Tagging Jobs

To enhance organization and searchability, you can assign tags to jobs.

optimizer = StrangeworksOptimizer(model=model, solver=solver, options=options, tags=["tag1", "tag2"])
sw_job = optimizer.run()

To find jobs by tag, use the jobs_by_tag method. You can filter by multiple tags and specify whether to use AND or OR for the search.

job_list = optimizer.jobs_by_tag(tags=["new-test-tag", "another-test-tag", "athird-test-tag"], andor="AND")

job_list = optimizer.jobs_by_tag(tags=["new-test-tag", "another-test-tag", "athird-test-tag"], andor="OR")

Download a Run

If you want to fetch a previously submitted run for resubmission or to inspect the contents, you can use the download_input_file method to recreate the optimizer used to run the job:

optimization_job = optimizer.download_input_file(sw_job.slug)

Download a Model

To see the input model used for a previous job use the download_input_model method of the StrangeworksOptimizer class:

model = optimizer.download_input_model(job_slug)

print(type(model))

Remote Jobs

The maximum optimization problem you may submit directly to the Strangeworks platform is limited to 32MB.

When running more complex models, first upload the problem to the Strangeworks platform and then submit a RemoteFile.

import strangeworks as sw
from strangeworks_optimizer import StrangeworksOptimizer
from dimod import BinaryQuadraticModel

sw.authenticate('your-api-key')

linear = {1: -2, 2: -2, 3: -3, 4: -3, 5: -2}
quadratic = {(1, 2): 2, (1, 3): 2, (2, 4): 2, (3, 4): 2, (3, 5): 2, (4, 5): 2}
bqm = BinaryQuadraticModel(linear, quadratic, "BINARY")

model = StrangeworksOptimizer().upload_model(bqm)

# model_url = model.model_url
# model_type = model.model_type

This RemoteFile can be submitted directly to the platform.

solver = 'your.solver'
optimizer = StrangeworksOptimizer(model=model, solver=solver, options=options)
sw_job = optimizer.run()

If you want to re-submit a remote model you must first retrieve the model_url and model_type. Accepted model_type values are (see Models for more information):

  • BinaryQuadraticModel
  • ConstrainedQuadraticModel
  • DiscreteQuadraticModel
  • JiJProblem
  • AquilaModel
  • QuboDict
  • MPSFile
  • HitachiModel
  • FujitsuModel
  • MatrixMarket
  • QplibFile
from strangeworks_optimization_models.problem_models import RemoteFile

model = RemoteFile(model_url, model_type)

Download Model

Once you have obtained the url of the file, you can retrieve it using:

model = optimizer.download_input_model_from_url(file_url)

print(type(model))

Download Remote Job Model

If you want to to download a job model for a remote job, the model used in that job was a RemoteFile, so by default download_input_model will not download the model itself, just the remote model with a pointer URL. It is possible to specify that you want the original model by using the option download_remote=True.

model = optimizer.download_input_model(job_slug, download_remote=True)

print(type(model))

Batching Jobs

You can run multiple jobs in parallel by using a batch.yaml file (see Remote Jobs for how to produce a model_url):

job_name: BatchJob
runs:
- run: "rundwave1"
problem_parameters:
model_url: "https://api.strangeworks.com/workspace//files/"
model_type: "BinaryQuadraticModel"
solver: "dwave.Advantage_system6.4"
solver_options:
num_reads: 50
chain_strength: 30

- run: "rundwave2"
problem_parameters:
model_url: "https://api.strangeworks.com/workspace//files/"
model_type: "BinaryQuadraticModel"
solver: "dwave.Advantage2_prototype2.2"
solver_options:
num_reads: 50
chain_strength: 30

- run: "rungurobi1"
problem_parameters:
model_url: "https://api.strangeworks.com/workspace//files/"
model_type: "BinaryQuadraticModel"
solver: "gurobi.qubo"
solver_options:
TimeLimit: 100
WorkLimit: 1000
Cutoff: 10
BarIterLimit: 1000
BestBdStop: 10
BestObjStop: 10

and the run_batch method to retrieve a list of Jobs.

batch_file = "batch.yaml"

optimizer = StrangeworksOptimizer()
sw_jobs = optimizer.run_batch(batch_file=batch_file)