Skip to main content

Strangeworks VQE

The strangeworks-vqe package allows users to run construct and solve problems with the QAOA algorithm on multiple hardware providers.

📑 Package Documentation


The VQE algorithm allows you to solve quantum mechanical problems by making use of the power of quantum hardware. It is a classical-quantum hybrid algorithm: the general idea is that we propose a quantum ansatz circuit with some variational parameters as the coefficients for some of the quantum gates. We then apply this circuit to our qubits, measure the output and repeat many times in order to build up the required statistics. We take these measurement results and compute the cost function with our defined problem. We then hand the algorithm over to a classical CPU which optimizes the circuit parameters before passing back to the quantum side to re-measure the cost function but now for the new parameterized quantum circuit. The algorithm then iterates back and forth between the application of the quantum circuit and the classical optimization of the circuit parameters before eventually converging on a minimum energy.

This page will describe how to install and begin to use the VQE service. ​


In order to use the AWS Hybrid job service and/or the IBM Cloud devices, the user must have a billing account properly enabled. Without this, the user can still utilize qiskit runtime jobs through IBMs free services. ​


To get started, make sure you have Python 3.9 or above (installation) and are familiar with setting up and using virtual environments.

Install packages using pip: ​

pip install strangeworks
pip install strangeworks-vqe

​ Import package into python: ​

from strangeworks_vqe.sdk import StrangeworksVQE


Any issues authenticating, you may need to add a QAOA resource to your account through the Platform,


Before running:

  1. Set up your environment and install strangeworks-vqe and strangeworks
  2. In the portal, Activate Strangeworks VQE Service to create a Resource
  3. Replace your-api-key with your key from the Portal homepage
  4. Use examples below to utilize the various functionality. See Examples section below for an example script.

Authenticate with strangeworks python sdk using users API token:


​ Get QAOA resource using qaoa sdk extension and users resource slug:

sw_vqe = StrangeworksVQE(resource_slug=" "))

​ List compatable backends for the qaoa product:


​ List all user qaoa jobs:

jobs = sw_vqe.job_list(update_status=True)

​ Run problem:

sw_job =, problem, problem_params)

​ Retrieve job with specific slug:

sw_job =[0]

​ Check the status of job and update

status = sw_vqe.update_status(sw_job)

Display results

result = sw_vqe.get_results(sw_job,calculate_exact_sol=True, display_results=True)


Here is an example run for a small problem on an IBM simulator:

import strangeworks
from strangeworks_vqe.sdk import StrangeworksVQE
import strangeworks_vqe.utils as utils

strangeworks.authenticate(api_key=" ", store_credentials=False)
sw_vqe = StrangeworksVQE(resource_slug=" ")

nqubits = 4
Jz = 0.5
Jxy = 1
H = utils.get_Heisenberg_PauliSumOp(nqubits, Jz, Jxy)

maxiter = 20
shotsin = 100
optimizer = "NELDER_MEAD"
ansatz = "RealAmplitudes"

problem_params = {
"maxiter": maxiter,
"shotsin": shotsin,
"nqubits": nqubits,
"optimizer": optimizer, # optional
"ansatz": ansatz, # optional

backend = "ibmq_qasm_simulator"
sw_job =, H, problem_params)

result = sw_vqe.get_results(sw_job,calculate_exact_sol=True, display_results=True)

🥳 Success! You may view your job in the portal.

😅 Something went wrong? Find us in Slack!


This section provides troubleshooting tips for the product or service this page covers. ​ ​ ​