Skip to content
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

The mcrx gate introduces unwanted phases #3536

Closed
quantumjim opened this issue Dec 3, 2019 · 5 comments
Closed

The mcrx gate introduces unwanted phases #3536

quantumjim opened this issue Dec 3, 2019 · 5 comments
Labels
priority: medium status: needs information Further information is requested

Comments

@quantumjim
Copy link
Member

quantumjim commented Dec 3, 2019

Information

  • Qiskit Terra version: 0.10.0
  • Python version:
  • Operating system:

What is the current behavior?

The mcrx gate for angle pi should (if I'm not mistaken, be equivalent to cx. This means it should be described by the matrix

1  0  0  0
0  1  0  0
0  0  0  1
0  0  1  0

However, the gate seems to introduce unwanted phases, making the effect seem to be better described by

1  0  0  0
0  1  0  0
0  0  0 -i
0  0 -i  0

So it is perhaps more of a controlled-Y than controlled-X.

Steps to reproduce the problem

See this notebook.

For example, the following should rotate |01> to |11>,

qc = QuantumCircuit(2)
ket = [0,1,0,0]
qc.initialize(ket,qc.qregs[0])

qc.mcrx(np.pi,[qr[0]],qr[1])

ket = execute(qc,Aer.get_backend('statevector_simulator')).result().get_statevector()
for amp in ket:
    print(amp)

Instead it rotates it to -i |11>

What is the expected behavior?

Suggested solutions

@1ucian0 1ucian0 added bug Something isn't working priority: medium labels Dec 3, 2019
@chriseclectic
Copy link
Member

chriseclectic commented Dec 5, 2019

mcrx is not equivalent to mcx because the RxGate cannot generate an X gate, only an +/-iX gate.

RXGate(a) = exp(-i * 0.5 * a * X), and so RXGate(pi) = -iX

Hence CRX(pi) = I ⊗ |0><0| -iX ⊗ |1><1| so the returned matrix/final state looks correct to me.

@chriseclectic chriseclectic removed the bug Something isn't working label Dec 5, 2019
@1ucian0 1ucian0 added the status: needs information Further information is requested label Dec 6, 2019
@1ucian0
Copy link
Member

1ucian0 commented Dec 6, 2019

Hi @quantumjim

Is #3536 (comment) solving this issue?

@quantumjim
Copy link
Member Author

I suppose this comes down to a conflict of convention. Both for mcrx, and for my proposed inclusion of crx in #3535.

The current convention seems to be that that crx acts the same as rx when the control is |1〉, but I'd prefer the convention that crx acts as cx when theta=pi.

I suppose the current convention is consistent with that for cu3, as set in #2755. So I guess I am probably in the minority here. But perhaps we can add a note in the docs to clarify?

@chriseclectic
Copy link
Member

@quantumjim I disagree strongly. Rx gate is well defined as exp(-1j * theta * X/2), so any added crx/mcrx gate should use that convention.

This will be better documented in PR #3472 which actually adds the matrix definition for every standard gate to the API documentation. After that PR is finished you can set the phases on gates so you could always make your own controlled gate of RxGate(theta, phase=pi/2) and then you could use that to generate a correct CX gate at theta=pi

@quantumjim
Copy link
Member Author

That looks great, and will serve the purposes of difficult people like me ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium status: needs information Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants