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

Bug in cu3 implementation #86

Closed
yoonbo opened this issue Sep 26, 2017 · 3 comments
Closed

Bug in cu3 implementation #86

yoonbo opened this issue Sep 26, 2017 · 3 comments

Comments

@yoonbo
Copy link

yoonbo commented Sep 26, 2017

cu3(pi, 0, pi) gate should work as controlled X gate, but it is not.

Expected Behavior

cx: (1, 0) ---> (0, 1)
cu3(pi, 0, pi) : (1, 0) ---> (0, 1)

Current Behavior

cx: (1, 0) ---> (0, 1)
cu3(pi, 0, pi) : (1, 0) ---> (0, -i)

Steps to Reproduce (for bugs)

import numpy as np

sys.path.append("../qiskit-sdk-py/")

from qiskit import QuantumProgram
import Qconfig

np.set_printoptions(precision=2)

Q_program = QuantumProgram()
n = 2
q = Q_program.create_quantum_register('q', n)
c = Q_program.create_classical_register('c', n)
  
state = Q_program.create_circuit('bug', [q], [c])

state.x(q[0])
state.cx(q[0], q[1])

state.measure(q[1], c[1])

backend = 'local_qasm_simulator'
result = Q_program.execute(['bug'], backend=backend, shots=1, silent = True)
print("Controlled X gate:")
print(result.get_data('bug')['quantum_state'])

print("")


Q_program = QuantumProgram()
n = 2
q = Q_program.create_quantum_register('q', n)
c = Q_program.create_classical_register('c', n)
  
state = Q_program.create_circuit('bug', [q], [c])

state.x(q[0])
state.cu3(np.pi, 0.0, np.pi, q[0], q[1])

state.measure(q[1], c[1])

backend = 'local_qasm_simulator'
result = Q_program.execute(['bug'], backend=backend, shots=1, silent = True)
print("CU3(pi, 0, pi) gate:")
print(result.get_data('bug')['quantum_state'])

Above code prints out

Controlled X gate:
[ 0.+0.j  0.+0.j  0.+0.j  1.+0.j]

CU3(pi, 0, pi) gate:
[  0.00e+00+0.j   0.00e+00+0.j   0.00e+00+0.j   6.12e-17-1.j]

Your Environment

  • Version used: 0.3.5
  • Environment name and version (e.g. Python 3.6.1): Python 3.6.2
  • Operating System and version: OSX
@rraymondhp
Copy link
Contributor

rraymondhp commented Sep 27, 2017

Hi,

But, essentially the state
[ 0.+0.j 0.+0.j 0.+0.j 1.+0.j] and the state
[ 0.00e+00+0.j 0.00e+00+0.j 0.00e+00+0.j 6.12e-17-1.j]
are the same up to global phase -j. I have confirmed that the cu3 with target 1 results in essentially the same state with cx up to the global phase -j.

Please refer to:
https://en.wikipedia.org/wiki/Quantum_state
... A unit vector is usually picked, but its phase factor can be chosen freely anyway. Nevertheless, such factors are important when state vectors are added together to form a superposition.

@jaygambetta
Copy link
Member

@yoonbo and @rraymondhp this is correct. It is not a bug it is just a global phase that quantum computers can't be see. I suggest if you look at |<psi_expected|psi_made>|^2 and if this is one then the states are the same.

@rraymondhp
Copy link
Contributor

Thanks. I also wrote about the global phase equivalence of u3 gate in the tutorial below:
https://nbviewer.jupyter.org/github/QISKit/qiskit-tutorial/blob/master/1_introduction/quantum_gates_and_linear_algebra.ipynb

taalexander pushed a commit to taalexander/qiskit-terra that referenced this issue May 2, 2019
* moved Aer tutorial images to /docs/images/figures/

and all references to these images

* Have Makefile point to correct Aqua and Chemistry directories

Fixes Qiskit#88

* Revert "Have Makefile point to correct Aqua and Chemistry directories"

This reverts commit fee13ba87e1888c88a997430ee0a57969a9985ac.

* Create community_qiskit.rst

* Revert "Create community_qiskit.rst"

This reverts commit 5fd2cafd6d2e570488e9985f26d33a0f5088c581.

* update global install instructions

Motivation: to synthesize the mostly duplicate install instructions currently under each Qiskit element's doc section, which can then be removed.

Direct to CONTRIBUTING files in each element's repo for instructions to build from source, since this serves a niche persona and is lengthy.

Added images for steps that involve pointing and clicking through the web.

Rewrote material for additional clarity.

* removed Troubleshooting section

fixes Qiskit#97

* simplify the ibm q provider documentation

Fixes Qiskit#86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants