03 - Running on the IBMQ cloud simulators, QVM or QPU
We have seen examples of running QAOA on mostly simulators. However, we may also want to run them on the the Pyquil’s QVM, IBMQ cloud simulators or even the real QPU. We demonstrate here the usage of such devices on OpenQAOA. The cloud devices would require the user to pass a set of credentials provided by the device hosts, for instance, IBMQ credentials for devices hosted on IBMQ cloud. For running computations on Rigetti’s devices the user can assign specific device specific arguments (for
e.g. as_qvm
) during the device creation. The users must also remember that they should run qvm
and quilc
processes on their machines to use Rigetti simulators. For more information on this, see Rigetti’s docs.
For the purpose of this notebook, we will try to optimize a Number Partition problem. For easy problem creation, we will use the in-built OpenQAOA NumberPartition
class.
Begin by importing necessary modules
[1]:
#import problem classes from OQ for easy problem creation
from openqaoa.problems import NumberPartition
#import the QAOA workflow model
from openqaoa import QAOA
#import method to specify the device
from openqaoa.backends import create_device
#Import IBMQ
from qiskit import IBMQ
Step 1: Create a problem instance
We begin by creating a random problem instance using the NumberPartition class.
We can also visualize the corresponding QUBO and verify that NumberPartition indeed produces a fully-connected QUBO problem with the following the steps: - Extract the Hamiltonian from the QUBO problem - Use the utility function to convert the Hamiltonian into its corresponding graph - Use the graph plotter to visualize the obtained graph.
NOTE: Converting the Hamiltonian to a graph loses information on the constant factor
[2]:
# Find partition of a list of 7 numbers generated randomly
prob = NumberPartition.random_instance(n_numbers=7)
prob_qubo = prob.qubo
[3]:
# visualize the QUBO form on a graph
from openqaoa.utilities import plot_graph, graph_from_hamiltonian
#extract Hamiltonain
cost_hamil = prob_qubo.hamiltonian
#convert Hamiltonian to graph
cost_gr = graph_from_hamiltonian(cost_hamil)
#plot the graph
plot_graph(cost_gr)
[4]:
print(prob_qubo.asdict())
{'terms': [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 6]], 'weights': [72.0, 108.0, 36.0, 12.0, 84.0, 96.0, 108.0, 36.0, 12.0, 84.0, 96.0, 54.0, 18.0, 126.0, 144.0, 6.0, 42.0, 48.0, 14.0, 16.0, 112.0], 'constant': 276, 'n': 7, 'problem_instance': {'problem_type': 'number_partition', 'numbers': [6, 6, 9, 3, 1, 7, 8], 'n_numbers': 7}, 'metadata': {}}
### Extract the exact solution
[5]:
# import the brute-force solver to obtain exact solution
from openqaoa.utilities import ground_state_hamiltonian
energy, configuration = ground_state_hamiltonian(cost_hamil)
print(f"Ground State energy: {energy}, Solution: {configuration}")
Ground State energy: 0.0, Solution: ['1100110', '0011110', '1100001', '0011001']
Step 2: Build the QAOA model on QPUs and cloud simulators
Initialize the model (with default parameters)
Optionally set the following properties for the model
model.set_device(...)
: Set the deviceThe device properties include the location of the device
[local, qcs, ibmq]
and the device name. Full list of devices available atopenqaoa.workflows.parameters.qaoa_parameters.ALLOWED_DEVICES
model.set_circuit_properties(...)
: Sets the circuit properties. Mainly used for:p
: the number of layersparam_type
: the desired parameterisation to be chosen between['standard', 'extended', 'fourier', annealing]
init_type
: the initialisation strategy for param_type. To be chosen between['ramp', 'random', 'custom']
model.set_backend_properties(...)
model.set_classical_optimizer(...)
For more details on the configurable properties, please refer to the documentation
Demo for IBMQ cloud simulators and QPUs
[6]:
qpu_credentials ={
"hub": "ibm-q",
"group": "open",
"project": "main"
}
To make our tests run, we load our own credentials which have been pre-loaded through IBMQ.save_account
[7]:
# initialize model with default configurations
q_qiskit = QAOA()
[8]:
# device. If qpu_crendetials is not specified,the default hub, group and provider is used.
qiskit_cloud = create_device(location='ibmq', name='ibm_kyoto', **qpu_credentials, as_emulator=True)
q_qiskit.set_device(qiskit_cloud)
# circuit properties
q_qiskit.set_circuit_properties(p=1, param_type='standard', init_type='rand', mixer_hamiltonian='x')
# backend properties (already set by default)
q_qiskit.set_backend_properties(prepend_state=None, append_state=None)
# classical optimizer properties
q_qiskit.set_classical_optimizer(method='nelder-mead', maxiter=20, cost_progress=True,
parameter_log=True, optimization_progress=True)
[9]:
q_qiskit.compile(prob_qubo)
# to use routing, pass your custom function as below
# q_qiskit.compile(prob_qubo, routing_function = my_custom_routing)
[10]:
print(q_qiskit.backend.parametric_circuit.count_ops()["cx"])
q_qiskit.backend.parametric_circuit.draw()
42
[10]:
[11]:
q_qiskit.optimize()
For Rigetti
[12]:
rigetti_args ={
'as_qvm':True,
'execution_timeout':10,
'compiler_timeout':100
}
[13]:
# initialize model with default configurations
q_pyquil = QAOA()
[14]:
# device
# rigetti_device = create_device(location='qcs', name='Aspen-M-3', **rigetti_args)
rigetti_device = create_device(location='qcs', name='7q-qvm', **rigetti_args)
q_pyquil.set_device(rigetti_device)
# circuit properties
q_pyquil.set_circuit_properties(p=1, param_type='standard', init_type='rand', mixer_hamiltonian='x')
# backend properties (already set by default)
q_pyquil.set_backend_properties(prepend_state=None, append_state=None)
# classical optimizer properties
q_pyquil.set_classical_optimizer(method='nelder-mead', maxiter=200, cost_progress=True,
parameter_log=True, optimization_progress=True)
Step 3: Compile and Optimize
Once the QAOA model is configured, we need to compile it. Compilation is necessary because the QAOA solver has to interact with the problem in to be able to create the underlying QAOA circuit.
The problem is ready to be optimized now. The user can call
model.optimize()
to initiate the optimization loop.
[15]:
q_pyquil.compile(prob_qubo)
# to use routing, pass your custom function as below
# q_pyquil.compile(prob_qubo, routing_function = my_custom_routing)
[16]:
print(q_pyquil.backend.qaoa_circuit(q_pyquil.variate_params))
DECLARE twoQ_COST_seq0_layer0 REAL[1]
DECLARE twoQ_COST_seq1_layer0 REAL[1]
DECLARE twoQ_COST_seq2_layer0 REAL[1]
DECLARE twoQ_COST_seq3_layer0 REAL[1]
DECLARE twoQ_COST_seq4_layer0 REAL[1]
DECLARE twoQ_COST_seq5_layer0 REAL[1]
DECLARE twoQ_COST_seq6_layer0 REAL[1]
DECLARE twoQ_COST_seq7_layer0 REAL[1]
DECLARE twoQ_COST_seq8_layer0 REAL[1]
DECLARE twoQ_COST_seq9_layer0 REAL[1]
DECLARE twoQ_COST_seq10_layer0 REAL[1]
DECLARE twoQ_COST_seq11_layer0 REAL[1]
DECLARE twoQ_COST_seq12_layer0 REAL[1]
DECLARE twoQ_COST_seq13_layer0 REAL[1]
DECLARE twoQ_COST_seq14_layer0 REAL[1]
DECLARE twoQ_COST_seq15_layer0 REAL[1]
DECLARE twoQ_COST_seq16_layer0 REAL[1]
DECLARE twoQ_COST_seq17_layer0 REAL[1]
DECLARE twoQ_COST_seq18_layer0 REAL[1]
DECLARE twoQ_COST_seq19_layer0 REAL[1]
DECLARE twoQ_COST_seq20_layer0 REAL[1]
DECLARE oneQ_MIXER_seq0_layer0 REAL[1]
DECLARE oneQ_MIXER_seq1_layer0 REAL[1]
DECLARE oneQ_MIXER_seq2_layer0 REAL[1]
DECLARE oneQ_MIXER_seq3_layer0 REAL[1]
DECLARE oneQ_MIXER_seq4_layer0 REAL[1]
DECLARE oneQ_MIXER_seq5_layer0 REAL[1]
DECLARE oneQ_MIXER_seq6_layer0 REAL[1]
DECLARE ro BIT[7]
RZ(pi) 0
RX(pi/2) 0
RZ(pi/2) 0
RX(-pi/2) 0
RZ(1.0*twoQ_COST_seq0_layer0[0]) 0
RZ(pi) 1
RX(pi/2) 1
RZ(pi/2) 1
RX(-pi/2) 1
RZ(1.0*twoQ_COST_seq0_layer0[0]) 1
RX(pi/2) 1
RZ(pi/2) 1
RX(-pi/2) 1
RZ(pi) 1
CZ 0 1
RZ(3.4766597857314725) 0
RX(pi/2) 1
RZ(pi/2) 1
RX(-pi/2) 1
RZ(-2*pi + 1.0*twoQ_COST_seq0_layer0[0]) 1
RX(pi/2) 1
RZ(pi/2) 1
RX(-pi/2) 1
RZ(2.8065255214481253) 1
CZ 0 1
RZ(-0.3350671321416665 + -1.0*twoQ_COST_seq0_layer0[0] + 1.0*twoQ_COST_seq1_layer0[0]) 0
RZ(pi) 2
RX(pi/2) 2
RZ(pi/2) 2
RX(-pi/2) 2
RZ(1.0*twoQ_COST_seq1_layer0[0]) 2
RX(pi/2) 2
RZ(pi/2) 2
RX(-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 6
RZ(-pi + 1.0*twoQ_COST_seq20_layer0[0]) 6
RX(pi/2) 6
RZ(pi/2) 6
RX(-pi/2) 6
RZ(pi) 6
CZ 5 6
RX(pi/2) 6
RZ(pi/2) 6
RX(-pi/2) 6
RZ(-pi/2 + -1.0*twoQ_COST_seq20_layer0[0]) 6
RX(pi/2) 6
RZ(1.0*oneQ_MIXER_seq6_layer0[0]) 6
RX(-pi/2) 6
RZ(-pi/2) 6
MEASURE 6 ro[6]
RZ(-pi/2 + -1.0*twoQ_COST_seq20_layer0[0]) 5
RX(pi/2) 5
RZ(1.0*oneQ_MIXER_seq5_layer0[0]) 5
RX(-pi/2) 5
RZ(-pi/2) 5
MEASURE 5 ro[5]
HALT
[17]:
q_pyquil.optimize()
Accessing the results
The process of obtaining the results for models with either device looks exactly the same. Therefore, to keep this notebook succinct, we only analyze results produced by one device.
[18]:
opt_results = q_qiskit.result
[19]:
# print the cost history
opt_results.plot_cost()
[20]:
opt_results = q_pyquil.result
[21]:
# print the cost history
opt_results.plot_cost()
[22]:
# prints a large output (commented by default)
# pprint(opt_results.intermediate)
[23]:
print(opt_results.optimized)
{'angles': [1.561421383292, 0.769176645749], 'cost': 191.28, 'measurement_outcomes': Counter({'0000001': 4, '1110100': 4, '1011010': 4, '1101010': 4, '0100111': 3, '0000011': 3, '0011110': 3, '1111000': 3, '1100010': 2, '0011000': 2, '0111101': 2, '1010100': 2, '0010001': 2, '0011100': 2, '0001101': 2, '1001110': 2, '0101110': 2, '1000111': 2, '1010110': 2, '0101100': 2, '1110111': 1, '0011111': 1, '1010010': 1, '1111010': 1, '1110110': 1, '1100100': 1, '1010101': 1, '0100100': 1, '1100111': 1, '0001110': 1, '0100101': 1, '1100001': 1, '1011110': 1, '1000010': 1, '0111110': 1, '1000100': 1, '0101111': 1, '1111101': 1, '0101101': 1, '1011101': 1, '1111100': 1, '1010001': 1, '1001000': 1, '0001001': 1, '0110100': 1, '0100001': 1, '1101100': 1, '0110111': 1, '0101001': 1, '1000001': 1, '0001011': 1, '0110110': 1, '1100110': 1, '1011111': 1, '0110010': 1, '1000011': 1, '1001011': 1, '1101011': 1, '1001111': 1, '1010000': 1, '0000010': 1, '0101011': 1, '1100011': 1, '1111111': 1, '0010110': 1, '1010011': 1, '1101101': 1, '1110010': 1}), 'job_id': '4943128c-d880-4593-9032-03841912541d', 'eval_number': 503}
[24]:
opt_results.most_probable_states
[24]:
{'solutions_bitstrings': ['0000001', '1110100', '1011010', '1101010'],
'bitstring_energy': 576.0}
[ ]: