-
Notifications
You must be signed in to change notification settings - Fork 376
Use Operator rather than unitary simulator to convert circuit to unitary matrix #1224
Conversation
39cda1b
to
466bd48
Compare
The unitary simulator does not account for the global phase in a circuit. qiskit.quantum_info.Operator does account for global phase when converting (when possible) a circuit to a unitary matrix. Closes qiskit-community#1218
This should be GTG. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏼 about the TODO/NOTE comments, are they still open or could
you check if they can be removed?
I'll check. This should probably be resolved before committing. |
We discussed BasicAer in the past https://github.com/Qiskit/qiskit-aqua/issues/1003. I remember there were some concerns. Is it clear now? I made a PoC for the discussion #1009. |
@t-imamichi Are you asking is it clear about the removal of BasicAer etc as was originally discussed in the issue and PoC PR? To my knowledge nothing further has happened. This PR is just about addressing some internal logic, where the issue as stated is incorrect global phase in the result - I think internal use within Aqua was aspect 2 in your original issue - where it uses BasicAer say for statevector or unitary conversion. Maybe more internal aspects could be changed if it was lower overhead, better performance etc. This was one such internal use where the outcome was just not correct and noticed as part of the phase estimation work and needed to be addressed. |
Thanks. I got it. |
Sorry, @t-imamichi I missed your comment till just now.
|
Yes, they can be removed. EDIT: The comments have been removed |
Using Operator(QuantumCircuit) gives the same qubit ordering that the previous unitary-simulator-based code did. I removed the comment entirely because the behavior depends only on Operator(QuantumCircuit), which is not obscure.
@jlapeyre Sorry for confusing you. This PR does not have the problem we discussed in #1003. |
…ary matrix (qiskit-community#1224) * Fix factor of 2 error in converting exp_i to rotation gates * Make CircuitOp use Operator rather than unitary simulator to get matrix The unitary simulator does not account for the global phase in a circuit. qiskit.quantum_info.Operator does account for global phase when converting (when possible) a circuit to a unitary matrix. Closes qiskit-community#1218 * Remove note on reversing order of qubits Using Operator(QuantumCircuit) gives the same qubit ordering that the previous unitary-simulator-based code did. I removed the comment entirely because the behavior depends only on Operator(QuantumCircuit), which is not obscure.
…ary matrix (qiskit-community#1224) * Fix factor of 2 error in converting exp_i to rotation gates * Make CircuitOp use Operator rather than unitary simulator to get matrix The unitary simulator does not account for the global phase in a circuit. qiskit.quantum_info.Operator does account for global phase when converting (when possible) a circuit to a unitary matrix. Closes qiskit-community#1218 * Remove note on reversing order of qubits Using Operator(QuantumCircuit) gives the same qubit ordering that the previous unitary-simulator-based code did. I removed the comment entirely because the behavior depends only on Operator(QuantumCircuit), which is not obscure.
…ary matrix (qiskit-community/qiskit-aqua#1224) * Fix factor of 2 error in converting exp_i to rotation gates * Make CircuitOp use Operator rather than unitary simulator to get matrix The unitary simulator does not account for the global phase in a circuit. qiskit.quantum_info.Operator does account for global phase when converting (when possible) a circuit to a unitary matrix. Closes qiskit-community/qiskit-aqua#1218 * Remove note on reversing order of qubits Using Operator(QuantumCircuit) gives the same qubit ordering that the previous unitary-simulator-based code did. I removed the comment entirely because the behavior depends only on Operator(QuantumCircuit), which is not obscure.
…ary matrix (qiskit-community/qiskit-aqua#1224) * Fix factor of 2 error in converting exp_i to rotation gates * Make CircuitOp use Operator rather than unitary simulator to get matrix The unitary simulator does not account for the global phase in a circuit. qiskit.quantum_info.Operator does account for global phase when converting (when possible) a circuit to a unitary matrix. Closes qiskit-community/qiskit-aqua#1218 * Remove note on reversing order of qubits Using Operator(QuantumCircuit) gives the same qubit ordering that the previous unitary-simulator-based code did. I removed the comment entirely because the behavior depends only on Operator(QuantumCircuit), which is not obscure.
…ary matrix (qiskit-community/qiskit-aqua#1224) * Fix factor of 2 error in converting exp_i to rotation gates * Make CircuitOp use Operator rather than unitary simulator to get matrix The unitary simulator does not account for the global phase in a circuit. qiskit.quantum_info.Operator does account for global phase when converting (when possible) a circuit to a unitary matrix. Closes qiskit-community/qiskit-aqua#1218 * Remove note on reversing order of qubits Using Operator(QuantumCircuit) gives the same qubit ordering that the previous unitary-simulator-based code did. I removed the comment entirely because the behavior depends only on Operator(QuantumCircuit), which is not obscure.
Summary
Closes #1218
This PR makes (for example)
qiskit.aqua.operators.Z.exp_i().to_matrix()
return the correct matrix. It does two things:Z.exp_i()
previously returned a circuit containing a Z-rotation gate, but with angle incorrect by a factor of 2. This PR uses the correct factor. The PR corrects the same erroneous angle for X and Y rotations.CircuitOp
to a matrix used the Aer unitary simulator. It returns the wrong matrix by a global phase. This is probably due to rough edges in the new global phase support in Terra.qiskit.quantum_info.Operator
will also convert a circuit to a matrix, if possible. It does account for theglobal_phase
property.This PR still lacks a test and release note.EDIT: tests have been added.
EDIT: release note has been adde.