-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GlobalPhaseGate
generates an error when trying to generate Statevector
#10012
Comments
Thanks for this report - there were bound to be some more issues with 0q operations that #8272 missed. The matrix returned shouldn't be full shape (and can't - we don't pass that information to edit: having looked a little further, |
To add on to my edit: the code in |
Hi @jakelishman. Sorry, I just realized that saying that " What I meant is that in One thing that it's worth pointing out, is that the correct matrix is generated when using the >>> from math import pi
>>> from qiskit import QuantumCircuit
>>> from qiskit.quantum_info import Operator
>>> from qiskit.circuit.library import GlobalPhaseGate
>>> qc = QuantumCircuit(2)
>>> qc.append(GlobalPhaseGate(pi/3))
>>> print(Operator(qc))
Operator([[0.5+0.8660254j, 0. +0.j , 0. +0.j , 0. +0.j ],
[0. +0.j , 0.5+0.8660254j, 0. +0.j , 0. +0.j ],
[0. +0.j , 0. +0.j , 0.5+0.8660254j, 0. +0.j ],
[0. +0.j , 0. +0.j , 0. +0.j , 0.5+0.8660254j]],
input_dims=(2, 2), output_dims=(2, 2)) What I noticed is that when creating an |
My point is that the global phase gate is of the correct size already - it's a 0q operator, so it matches your definition, and |
I changed my mind again: I think actually treating the If you'd like to make the PR, please feel free to, otherwise I can do it no trouble. |
@jakelishman I see what you mean now; sorry for the confusion. I added a conditional for when both |
No worries, I've made #10031 that does the fix I think both you and I have described. |
Environment
What is happening?
Statevector
class generates atuple index out of range
error when a quantum circuit includes an instance of the recently-addedGlobalPhaseGate
.How can we reproduce the issue?
What should happen?
The issue seems to be related to how the operator used to evolve the initial state is being generated. This operator uses the instruction
.to_matrix()
method, which for theGlobalPhaseGate
results in a matrix of shape (1,1), which is basically an array containing the global phase being added. For example:For this to work correctly, the operator needs to be a diagonal matrix with the global phase value of shape (2^n_qubits, 2^n_qubits) instead of just the value itself.
Any suggestions?
I would volunteer to help with this, but if I am not mistaken, the
to_matrix()
method is inherited from theGate
class, so I can't think of an easy solution other than treatingGlobalPhaseGate
as a special case.The text was updated successfully, but these errors were encountered: