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()
Checking Job Status
Job progress can be monitored on the portal or through the SDK. The statuses include:
PENDING
: The job is queued for execution.RUNNING
: The job is currently being processed.COMPLETED
: The job has finished, and results are available.FAILED
: The job encountered an error during execution.
print(f"Job status: {optimizer.status(sw_job.slug)}")
Retrieving 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 Models
See the input model used for a previous job using the download_input_model
method of the StrangeworksOptimizer
class:
model = optimizer.download_input_model(job_slug, download_remote=False)
print(type(model))
If the model used in that job was a RemoteFile (see below), then by default it will not download the model itself. However, you can specify that you want the original model by including the field download_remote=True
.
Or if you do not have a job-slug but have the url of the file, you can use:
model = optimizer.download_input_model_from_url(file_url)
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)
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)