Skip to content

Instantly share code, notes, and snippets.

@Q-lds
Last active October 17, 2022 11:17
Show Gist options
  • Save Q-lds/ccd592d1eb5f9d94d2df5a13a0b9f212 to your computer and use it in GitHub Desktop.
Save Q-lds/ccd592d1eb5f9d94d2df5a13a0b9f212 to your computer and use it in GitHub Desktop.
The simplest OpenQAOA workflow
from openqaoa.problems.problem import NumberPartition
from openqaoa.devices import create_device
from openqaoa.workflows.optimizer import QAOA
# Create the problem statement
np_qubo = NumberPartition(numbers=[5,6,7,4]).get_qubo_problem()
# Set up the QAOA object and customise it
q = QAOA()
# Choose the number of layers, the parametrisation, and the mixer type
q.set_circuit_properties(p=1, param_type='standard', init_type='ramp', mixer_hamiltonian='x')
# Define the device you want to run your problem on using the create_device() function - Here we choose the local wavefunction simulator supported by OpenQAOA
qiskit_shot = create_device(location='local', name='qiskit.qasm_simulator')
q.set_device(qiskit_shot)
# backend properties
q.set_backend_properties(n_shots = 8000)
# Set the classical method used to optimiza over QAOA angles and its properties
q.set_classical_optimizer(method='cobyla', maxiter=200)
q.compile(np_qubo)
q.optimize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment