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

Fix phase of cu3 gate to be compatible with u3 gate definition #2755

Merged
merged 4 commits into from
Jul 20, 2019

Conversation

chriseclectic
Copy link
Member

Summary

Fixes #2703

Currently the cu3 gate is not a controlled u3 gate under the current definition. It differs by a local phase on the u3 gate (which would be an ignorable global phase on normal u3, but not when it is controlled). This adds an additional u1 gate the the definition of the cu3 gate so that it has the correct matrix definition.

Details and comments

Before this PR the following would return falls because the output unitary for cu3 was not equal (up to global phase) to I ⊗ |0X0| + U3(a, b, c) ⊗ |1X1|

import numpy as np
from qiskit import QuantumCircuit, execute, BasicAer
from qiskit.quantum_info.operators.predicates import matrix_equal

# U3 gate params
a, b, c = 0.2, 0.3, 0.4

# U3 gate
circ1 = QuantumCircuit(1)
circ1.u3(a, b, c, 0)

# CU3 gate
circ2= QuantumCircuit(2)
circ2.cu3(a, b, c, 0, 1)

job = execute([circ1, circ2], BasicAer.get_backend('unitary_simulator'))
result = job.result()

# Circuit unitaries
mat_u3 = result.get_unitary(0)
mat_cu3 = result.get_unitary(1)

# Target Controlled-U3 unitary
target = np.kron(mat_u3, np.diag([0, 1])) + np.kron(np.eye(2), np.diag([1, 0]))

matrix_equal(target, mat_cu3, ignore_phase=True) 

@1ucian0
Copy link
Member

1ucian0 commented Jul 29, 2019

Is this a fix for #546 also?

@chriseclectic
Copy link
Member Author

@1ucian0 yep

lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
…t#2755)

* fix phase of cu3 definition

* update changelog

* update unroller test for new cu3 def
@chriseclectic chriseclectic deleted the fix-cu3def branch November 14, 2019 15:11
1ucian0 pushed a commit to 1ucian0/qiskit-terra that referenced this pull request Nov 15, 2019
mergify bot pushed a commit that referenced this pull request Nov 20, 2019
…3.py (#3479)

* update qiskit/qasm/libs/qelib1.inc according to #2755

* re adjust the length

* test
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
…3.py (Qiskit#3479)

* update qiskit/qasm/libs/qelib1.inc according to Qiskit#2755

* re adjust the length

* test
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

Successfully merging this pull request may close these issues.

inconsistency between CU1 and CU3 gate definitions
3 participants