Open stfnmangini opened 2 years ago
This may well be related to the approximation_degree
setting of the transpiler in Terra (I think this bug might be related to Terra, not to Aer?), which is under quite a bit of discussion about design philosophy - see Qiskit/qiskit-terra#8043, for example. If you transpile with approximation_degree = 0
, I think that should have the behaviour you expect.
I agree on the problem being somewhere in the transpiler, probably using a low approximation_degree
. However I cannot obtain the exact unitary even if transpiling the circuit, playing with the optimization_level
and approximation_degree
.
I feel there is something going bad when going through the control
function, apparently overriding the user commands.
As for the appropriate page, you're probably right, I didn't know where to open this issue as I'm not sure of its origin 😅
When you're setting approximation_degree
, are you doing it in a separate transpile
pass, or trying to pass it through execute
? (We're in discussion about completely deprecating execute
, because it was only ever meant to be a quick "just run it" method, and doesn't allow full access to the transpiler.) The full path is usually:
from qiskit import Aer, transpile
circuit = ...
backend = Aer.get_backend("aer_simulator")
transpiled = transpile(circuit, backend, **transpile_options)
backend.run(transpiled).result().get_unitary()
As a faster check, you can also do qiskit.quantum_info.Operator(circuit)
to get the unitary of small-ish circuits without going to Aer.
At any rate, I'll transfer this over to Terra (no big deal).
Informations
What is the current behavior?
The implementation of controlled operation for arbitrary unitaries, for example generated via
qiskit.quantum_info.random_unitary
, is incorrect when the number of qubits in the unitary to be controlled is greater than three.To my understanding, there may be a problem with the circuit implementation of the random unitary when you ask it to be controlled, as some undesired approximation is happening somewhere. In fact, the problem is not present when trying to implement a controlled version of a circuit with an explicit form.
Steps to reproduce the problem
Pick a random unitary via
qiskit.quantum_info.random_unitary
and ask Qiskit to implement it on a quantum circuit.Then create a quantum circuit with a controlled version of the unitary defined above
The unitary implemented by the controlled circuit is not equal to the theoretical one when
num_qubits >= 3
, while is it correct for 1 and 2 qubits. My guess is that when Qiskit is asked to perform a controlled version, it only finds an approximate, rather than exact, circuital implementation of the unitary, without explicitly mentioning it.This does not happen if instead of an arbitrary unitary you use an explicit circuit, for example:
Version Information
What is the expected behavior?
The controlled unitary should be correct.
Suggested solutions
Inspect what happens when calling
controlled
on a unitary gate rather than an explicit circuit.