Strangeworks Optimization Service
The strangeworks
Python SDK allows users to submit quadratic unconstrained binary optimization (QUBO) problems using quantum computing through a REST API.
Overview​
The Strangeworks Quantum Optimization Service is designed to take in QUBO problems as input and optimize the problem using various backend samplers. The service allows for seamless integration with different sampler backends, ensuring that users can choose the most suitable solution for their problem. The optimized results are returned in a dictionary that corresponds to a dwave sampler's sample set.
This page will describe how to set up and begin to use the Quantum Optimization Service.
Prerequisites​
In order to use the Strangeworks Optimization Service, make sure you have Python 3.9 or above (installation) and are familiar with setting up and using virtual environments.
Installation​
Install packages using pip:
pip install strangeworks
pip install dimod
Import package into python:
import strangeworks
from dimod import BinaryQuadraticModel, SampleSet
import json
Authentication​
In the portal, activate Strangeworks Optimization Service to create a resource. Replace your-api-key
with your key from the Portal homepage.
Authenticate and configure the Python SDK:
strangeworks.authenticate('your-api-key')
Usage​
Before running:
- Set up your environment and install
strangeworks
. - Activate the Strangeworks Optimization Service to create a resource.
- Replace
your-api-key
with your key from the Portal homepage. - Use the examples below to utilize the various functionalities.
Access with Strangeworks SDK​
First get the resource:
resource = strangeworks.get_resource_for_product("optimization")
Submit the QUBO problem:
path = "qubo"
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")
qubo_job = {
"bqm": json.dumps(bqm.to_serializable()),
"var_type": "BINARY",
"lagrange_multiplier": 1.0,
"solver": {
"solver": "azure.Tabu",
"solver_options": {}
}
}
result = strangeworks.execute(resource, payload=qubo_job, endpoint=path)
sample_set = SampleSet.from_serializable(json.loads(result["samples"]))
# Print solutions
for s in sample_set:
print(s)
🥳 Success! You have successfully used the Strangeworks Optimization Service to solve a QUBO problem.
😅 Something went wrong? Find us in Slack!
Further Reading​
For more information on QUBO and quantum optimization, please refer to the following resources: