Closed Oussema-t closed 10 months ago
This is because you're passing an incorrect object to QuantumCircuit.append
. The append
method takes an Instruction
instance followed by a list of qubit specifiers, followed by a list of clbit specifiers, but you're instead passing a complete CircuitInstruction
context object from a different circuit in the first argument.
From what you've written, the circuit gate_decomposition
already appears to be the circuit you are trying to construct. Alternatively, you can merge one circuit into another while specifying the new qubits to act on using QuantumCircuit.compose
.
Thank you so much for your response, that was amazing from your part. I decompose my circuit using "gate_decomposition = two_qubit_cnot_decompose(unitary_matrix) " and run the second circuit, but still have different outputs from the second and the first one. I use the same simulator, but the state vectors for the first and the second are not the same !
I'm not sure what you mean by the statevectors not being equal; up to numerical tolerance, Aer produces the same unitary for both your circuit
and your gate_decomposition
as I see it.
The first one is the main circuit, and the second is the decomposed circuit !
When the two circuits are equal, they will provide the same state vectors?
The unitary Matrixes are not equal !
You can't expect bit-for-bit equality when the floating-point operations being performed are different, even if in "perfect" real-number mathematics they would produce the exact same result. In this case, both the decomposition itself and then the subsequent matrix multiplications to produce the unitary matrix have small error terms in them, and that's what you're seeing.
If you look at the elementwise magnitude of the difference, you can see that it's all on the order of 1e-15
, which is about what should be expected.
Thank you man, I didn't see the e-17!
Other question please ? Can we apply the decomposer for more than 2 qubits ?
Synthesis is a non-trivial problem in general; if you want general unitary synthesis for any number of qubits, you're most likely better off using a full compilation (transpile
) defining the target basis set, etc.
I'm going to close this issue now, because the problem is solved. If you have usage questions, I'd encourage you to take them to the Qiskit slack.
Environment
What is happening?
I try to add those gates of unitary matrix in new circuit, but still have error.
How can we reproduce the issue?
I can share my code:
What should happen?
The function (append) should add all gates from the unitary matrix to the necircuit
Any suggestions?
The function doesn't work, we should modify the parameters or something like that !