Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.16k stars 2.35k forks source link

QAOA fails if mixer includes parameterized mcrz #8301

Closed ejwilson3 closed 11 months ago

ejwilson3 commented 2 years ago

Environment

What is happening?

Submitting a QAOA with a custom mixer which includes a mcrz gate with a parameter (even if it's only controlled by a single qubit) it throws CircuitError: 'Cannot bind parameters(t[1]) not present in the circuit.

This doesn't happen with crz or mcp gates.

How can we reproduce the issue?

import qiskit
from qiskit.circuit import QuantumCircuit
from qiskit.algorithms import QAOA
from qiskit.algorithms.optimizers import COBYLA
from qiskit_optimization.algorithms import MinimumEigenOptimizer
quantum_instance = qiskit.utils.QuantumInstance(qiskit.Aer.get_backend('aer_simulator'))

mixer = QuantumCircuit(2)
beta = qiskit.circuit.Parameter('B')
mixer.mcrz(-1*beta, [0], 1)

# The phase separator doesn't matter, this is just an example
prog = qiskit_optimization.QuadraticProgram('example')
prog.binary_var('v1')
prog.binary_var('v2')
prog.minimize(quadratic={('v1', 'v2'): 1})

qaoa = MinimumEigenOptimizer(QAOA(mixer=mixer, optimizer=COBYLA(), reps=1, quantum_instance=quantum_instance))
result = qaoa.solve(prog)

Which ends up producing

File ~/Library/Python/3.8/lib/python/site-packages/qiskit/circuit/quantumcircuit.py:2577, in QuantumCircuit.assign_parameters(self, parameters, inplace)
   2571 params_not_in_circuit = [
   2572     param_key
   2573     for param_key in unrolled_param_dict
   2574     if param_key not in unsorted_parameters
   2575 ]
   2576 if len(params_not_in_circuit) > 0:
-> 2577     raise CircuitError(
   2578         "Cannot bind parameters ({}) not present in the circuit.".format(
   2579             ", ".join(map(str, params_not_in_circuit))
   2580         )
   2581     )
   2583 # replace the parameters with a new Parameter ("substitute") or numeric value ("bind")
   2584 for parameter, value in unrolled_param_dict.items():

CircuitError: 'Cannot bind parameters (t[1]) not present in the circuit.'

What should happen?

There should be no actual output for this code; there isn't one when using mcp or crz instead of mcrz, and result should be essentially the same as it is when using crz instead.

Any suggestions?

No response

woodsp-ibm commented 1 year ago

Although this talks about QAOA I think its more to do with the QAOAAnsatz from the circuit library which has the parameters and where things would bound. Hence while at first sight I was going to put the mod algorithms label on this, to deal with it appropriately when the algorithms are moved out, I did not since I don't think its the QAOA algorithm perse.

jakelishman commented 11 months ago

This should have been fixed by #11032. Feel free to reopen if that's not the case.