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

Deprecate QuantumCircuit.u1/2/3 #5083

Merged
merged 98 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from 97 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
9fe9807
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 1, 2020
5c75fbf
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 4, 2020
859506e
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 8, 2020
c8a0c3a
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 9, 2020
216ae14
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 14, 2020
f3f861b
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 17, 2020
570eef5
fix first round of deprecation warnings
Cryoris Sep 17, 2020
063d47b
fix more deprecation warnings
Cryoris Sep 17, 2020
3c815b0
add U/P to ast_to_dag
Cryoris Sep 17, 2020
202bf94
update examples
Cryoris Sep 17, 2020
af89759
update circuit library
Cryoris Sep 17, 2020
8347ed6
update controlled gates and UC
Cryoris Sep 17, 2020
dac79da
circlib
Cryoris Sep 18, 2020
dee3e7d
Apply suggestions from code review
Cryoris Sep 18, 2020
55336de
more deprecations
Cryoris Sep 18, 2020
6dd5baa
Merge branch 'deprecate-u123' of github.com:Cryoris/qiskit-terra into…
Cryoris Sep 18, 2020
a4ccdde
update deprecation warnings with sx-p decomps
Cryoris Sep 18, 2020
7425b6b
update test_parameters
Cryoris Sep 18, 2020
46c6709
update test_barrier_before_final_meas
Cryoris Sep 18, 2020
4c8ba08
example in qiskit/transpiler/__init__
Cryoris Sep 18, 2020
2d11435
update test_assembler
Cryoris Sep 18, 2020
347b2ec
test_circuit_to_instruction
Cryoris Sep 18, 2020
f015070
dagcircuit.test_compose
Cryoris Sep 18, 2020
6efd0f5
test_dagcircuit & dependency
Cryoris Sep 18, 2020
db86e4e
qi.test_synthesis
Cryoris Sep 18, 2020
fce30c3
qi operators/states
Cryoris Sep 18, 2020
22f7e05
test_basis_translator
Cryoris Sep 18, 2020
8aae9ea
test_collect_2q_blocks
Cryoris Sep 18, 2020
4fcbfb8
commutative analysis & cancellation
Cryoris Sep 18, 2020
b164f7d
transpiler.test_consolidate_blocks
Cryoris Sep 18, 2020
1f56401
transpiler.test_cx_direction
Cryoris Sep 18, 2020
c2dae14
transpiler.test_decompose
Cryoris Sep 18, 2020
c9f826a
transpiler.test_kak_over_optimization
Cryoris Sep 18, 2020
259a615
transpiler.test_optimize_1q_gates
Cryoris Sep 18, 2020
d309358
test_passmanager & preset_passmanagers
Cryoris Sep 18, 2020
b25bf13
transpiler.test_remove_diagonal_gates_before_measure
Cryoris Sep 18, 2020
730ae71
transpiler.test_stochastic_swap
Cryoris Sep 18, 2020
dd5a3e7
transpiler.test_unroller
Cryoris Sep 18, 2020
33f3a8f
visualization tests
Cryoris Sep 18, 2020
69d2fbe
randomized.test_synthesis
Cryoris Sep 18, 2020
4ada24a
scheduler.test_basic_scheduler
Cryoris Sep 18, 2020
b8d2e2b
pulse.test_builder
Cryoris Sep 18, 2020
d651ccc
qft examples
Cryoris Sep 18, 2020
7bf1df8
transpiler/graysynth
Cryoris Sep 18, 2020
f84ef35
fix qubit broadcast in U2
Cryoris Sep 18, 2020
344a7d7
fix lint
Cryoris Sep 18, 2020
a0da405
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 22, 2020
7ee18d0
Merge branch 'master' into deprecate-u123
Cryoris Sep 22, 2020
d1cfca2
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 22, 2020
1f0d48e
typo: circular->cyclic
Cryoris Sep 23, 2020
1c9ef4b
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 23, 2020
02d55ec
Merge branch 'master' into deprecate-u123
Cryoris Sep 23, 2020
5692a2b
Merge branch 'deprecate-u123' of github.com:Cryoris/qiskit-terra into…
Cryoris Sep 23, 2020
0cc270c
Merge branch 'master' into deprecate-u123
Cryoris Sep 24, 2020
5e8edf1
Merge branch 'deprecate-u123' of github.com:Cryoris/qiskit-terra into…
Cryoris Sep 25, 2020
d27c0b4
fix lint
Cryoris Sep 25, 2020
48fb740
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Sep 29, 2020
a38f18c
Merge branch 'master' into deprecate-u123
Cryoris Sep 29, 2020
6e23ce9
Merge branch 'master' into deprecate-u123
Cryoris Sep 30, 2020
3b7a577
Merge branch 'master' into deprecate-u123
Cryoris Oct 1, 2020
0a36533
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 2, 2020
5356a8b
Merge branch 'deprecate-u123' of github.com:Cryoris/qiskit-terra into…
Cryoris Oct 2, 2020
9f4db8d
fix lint from merge
Cryoris Oct 2, 2020
7719923
Merge branch 'master' into deprecate-u123
Cryoris Oct 3, 2020
a946196
Merge branch 'deprecate-u123' of github.com:Cryoris/qiskit-terra into…
Cryoris Oct 5, 2020
ee30eb3
rm deprecated call to u3
Cryoris Oct 5, 2020
cef504b
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 5, 2020
4732c65
Merge branch 'master' into deprecate-u123
Cryoris Oct 5, 2020
103d544
Merge branch 'master' into deprecate-u123
Cryoris Oct 6, 2020
7037890
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 6, 2020
b565cb3
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 7, 2020
1a6f53d
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 8, 2020
ff9f959
Update qiskit/circuit/quantumcircuit.py
Cryoris Oct 12, 2020
ac73fa9
Update qiskit/circuit/quantumcircuit.py
Cryoris Oct 12, 2020
5da47e2
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 12, 2020
607708f
apply suggestions from code review
Cryoris Oct 13, 2020
822773b
Merge branch 'master' into deprecate-u123
Cryoris Oct 13, 2020
6de85bc
make U a base gate
Cryoris Oct 13, 2020
78f8b1a
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 13, 2020
2d8128e
Merge branch 'master' into deprecate-u123
Cryoris Oct 13, 2020
9bd58c2
update tests to U as base gate
Cryoris Oct 13, 2020
5071f85
Merge branch 'deprecate-u123' of github.com:Cryoris/qiskit-terra into…
Cryoris Oct 13, 2020
86fa04c
Merge branch 'master' into deprecate-u123
ajavadia Oct 14, 2020
fe68ac5
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 14, 2020
e576223
temporarily run tutorials on aqua master
Cryoris Oct 14, 2020
436ca86
Merge branch 'deprecate-u123' of github.com:Cryoris/qiskit-terra into…
Cryoris Oct 14, 2020
8a59e20
wrong linenumber in todo
Cryoris Oct 14, 2020
08383dd
remove comment of old decomposition
Cryoris Oct 14, 2020
00a88e1
Merge branch 'master' into deprecate-u123
Cryoris Oct 14, 2020
ada8823
Merge branch 'master' into deprecate-u123
kdk Oct 14, 2020
8160d87
add reno
Cryoris Oct 14, 2020
c7a6d10
consistent use of pi symbol in warnings
Cryoris Oct 14, 2020
4f64b4b
Merge branch 'deprecate-u123' of github.com:Cryoris/qiskit-terra into…
Cryoris Oct 14, 2020
9cc0c25
Merge branch 'master' of github.com:Qiskit/qiskit-terra into master
Cryoris Oct 14, 2020
f0345fe
Merge branch 'master' into deprecate-u123
Cryoris Oct 14, 2020
0195724
update test to not use deprecated names
Cryoris Oct 14, 2020
4127a3f
fix messed up ff merge
Cryoris Oct 14, 2020
f568753
no clue where that » went
Cryoris Oct 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python

# TODO in L591 change git+https://github.com/Qiskit/qiskit-aqua back to "qiskit-aqua"
# after the joint release of Terra 0.16 and Aqua 0.8

trigger:
branches:
include:
Expand Down Expand Up @@ -585,7 +588,7 @@ stages:
python -m pip install --upgrade pip
pip install -U -r requirements.txt -r requirements-dev.txt -c constraints.txt
pip install -c constraints.txt -e .
pip install "qiskit-ibmq-provider" "qiskit-aer" "z3-solver" "qiskit-ignis" "qiskit-aqua" "pyscf<1.7.4" "matplotlib<3.3.0" sphinx nbsphinx sphinx_rtd_theme cvxpy -c constraints.txt
pip install "qiskit-ibmq-provider" "qiskit-aer" "z3-solver" "qiskit-ignis" git+https://github.com/Qiskit/qiskit-aqua "pyscf<1.7.4" "matplotlib<3.3.0" sphinx nbsphinx sphinx_rtd_theme cvxpy -c constraints.txt
python setup.py build_ext --inplace
sudo apt install -y graphviz pandoc
pip check
Expand Down
4 changes: 2 additions & 2 deletions examples/python/ibmq/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def input_state(circ, n):
"""n-qubit input state for QFT that produces output 1."""
for j in range(n):
circ.h(j)
circ.u1(-math.pi/float(2**(j)), j)
circ.p(-math.pi/float(2**(j)), j)


def qft(circ, n):
"""n-qubit QFT on q in circ."""
for j in range(n):
for k in range(j):
circ.cu1(math.pi/float(2**(j-k)), j, k)
circ.cp(math.pi/float(2**(j-k)), j, k)
circ.h(j)


Expand Down
6 changes: 4 additions & 2 deletions examples/python/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ def input_state(circ, n):
"""n-qubit input state for QFT that produces output 1."""
for j in range(n):
circ.h(j)
circ.u1(-math.pi/float(2**(j)), j)
circ.p(-math.pi/float(2**(j)), j)


def qft(circ, n):
"""n-qubit QFT on q in circ."""
for j in range(n):
for k in range(j):
circ.cu1(math.pi/float(2**(j-k)), j, k)
circ.cp(math.pi/float(2**(j-k)), j, k)
circ.h(j)


qft3 = QuantumCircuit(5, 5, name="qft3")
qft4 = QuantumCircuit(5, 5, name="qft4")
qft5 = QuantumCircuit(5, 5, name="qft5")
Expand Down
2 changes: 1 addition & 1 deletion examples/python/teleport.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
qc = QuantumCircuit(q, c0, c1, c2, name="teleport")

# Prepare an initial state
qc.u3(0.3, 0.2, 0.1, q[0])
qc.u(0.3, 0.2, 0.1, q[0])

# Prepare a Bell pair
qc.h(q[1])
Expand Down
16 changes: 9 additions & 7 deletions qiskit/circuit/add_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def control(operation: Union[Gate, ControlledGate],
if operation.definition is not None and operation.definition.global_phase:
global_phase += operation.definition.global_phase
else:
basis = ['u1', 'u3', 'x', 'rx', 'ry', 'rz', 'cx']
basis = ['p', 'u', 'x', 'rx', 'ry', 'rz', 'cx']
unrolled_gate = _unroll_gate(operation, basis_gates=basis)
for gate, qreg, _ in unrolled_gate.definition.data:
if gate.name == 'x':
Expand All @@ -130,13 +130,15 @@ def control(operation: Union[Gate, ControlledGate],
controlled_circ.mcrz(gate.definition.data[0][0].params[0],
q_control, q_target[qreg[0].index],
use_basis_gates=True)
elif gate.name == 'u1':
controlled_circ.mcu1(gate.params[0], q_control, q_target[qreg[0].index])
elif gate.name == 'p':
from qiskit.circuit.library import MCPhaseGate
controlled_circ.append(MCPhaseGate(gate.params[0], num_ctrl_qubits),
q_control[:] + [q_target[qreg[0].index]])
elif gate.name == 'cx':
controlled_circ.mct(q_control[:] + [q_target[qreg[0].index]],
q_target[qreg[1].index],
q_ancillae)
elif gate.name == 'u3':
elif gate.name == 'u':
theta, phi, lamb = gate.params
if phi == -pi / 2 and lamb == pi / 2:
controlled_circ.mcrx(theta, q_control, q_target[qreg[0].index],
Expand All @@ -162,10 +164,10 @@ def control(operation: Union[Gate, ControlledGate],
# apply controlled global phase
if ((operation.definition is not None and operation.definition.global_phase) or global_phase):
if len(q_control) < 2:
controlled_circ.u1(operation.definition.global_phase + global_phase, q_control)
controlled_circ.p(operation.definition.global_phase + global_phase, q_control)
else:
controlled_circ.mcu1(operation.definition.global_phase + global_phase,
q_control[:-1], q_control[-1])
controlled_circ.mcp(operation.definition.global_phase + global_phase,
q_control[:-1], q_control[-1])
if isinstance(operation, controlledgate.ControlledGate):
new_num_ctrl_qubits = num_ctrl_qubits + operation.num_ctrl_qubits
new_ctrl_state = operation.ctrl_state << num_ctrl_qubits | ctrl_state
Expand Down
6 changes: 3 additions & 3 deletions qiskit/circuit/library/arithmetic/quadratic_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self,
# constant coefficient
if offset != 0:
for i, q_i in enumerate(qr_result):
self.u1(scaling * 2 ** i * offset, q_i)
self.p(scaling * 2 ** i * offset, q_i)

# the linear part consists of the vector and the diagonal of the
# matrix, since x_i * x_i = x_i, as x_i is a binary variable
Expand All @@ -141,7 +141,7 @@ def __init__(self,
value += quadratic[j][j] if quadratic is not None else 0
if value != 0:
for i, q_i in enumerate(qr_result):
self.cu1(scaling * 2 ** i * value, qr_input[j], q_i)
self.cp(scaling * 2 ** i * value, qr_input[j], q_i)

# the quadratic part adds A_ij and A_ji as x_i x_j == x_j x_i
if quadratic is not None:
Expand All @@ -150,7 +150,7 @@ def __init__(self,
value = quadratic[j][k] + quadratic[k][j]
if value != 0:
for i, q_i in enumerate(qr_result):
self.mcu1(scaling * 2 ** i * value, [qr_input[j], qr_input[k]], q_i)
self.mcp(scaling * 2 ** i * value, [qr_input[j], qr_input[k]], q_i)

# add the inverse QFT
iqft = QFT(num_result_qubits, do_swaps=False).inverse()
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/basis_change/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def _build(self) -> None:
num_entanglements = max(0, self.num_qubits - max(self.approximation_degree, j))
for k in range(j + 1, j + num_entanglements):
lam = np.pi / (2 ** (k - j))
self.cu1(lam, j, k)
self.cp(lam, j, k)

if self.insert_barriers:
self.barrier()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def cx_chain(circuit, inverse=False):

basis_change(evo)
cx_chain(evo)
evo.u1(2.0 * time, indices[-1])
evo.p(2.0 * time, indices[-1])
cx_chain(evo, inverse=True)
basis_change(evo, inverse=True)
return evo
Expand Down
4 changes: 2 additions & 2 deletions qiskit/circuit/library/iqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def __init__(self, interactions: Union[List, np.array]) -> None:
for i in range(num_qubits):
for j in range(i+1, num_qubits):
if interactions[i][j] % 4 != 0:
inner.cu1(interactions[i][j] * np.pi / 2, i, j)
inner.cp(interactions[i][j] * np.pi / 2, i, j)

for i in range(num_qubits):
if interactions[i][i] % 8 != 0:
inner.u1(interactions[i][i] * np.pi / 8, i)
inner.p(interactions[i][i] * np.pi / 8, i)

inner.h(range(num_qubits))
all_qubits = self.qubits
Expand Down
2 changes: 1 addition & 1 deletion qiskit/circuit/library/n_local/excitation_preserving.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self,
swap.ryy(theta, 0, 1)
if mode == 'fsim':
phi = Parameter('φ')
swap.cu1(phi, 0, 1)
swap.cp(phi, 0, 1)

super().__init__(num_qubits=num_qubits,
rotation_blocks=RZGate,
Expand Down
18 changes: 12 additions & 6 deletions qiskit/circuit/library/standard_gates/equivalence_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@
q = QuantumRegister(1, 'q')
theta = Parameter('theta')
phase_to_u1 = QuantumCircuit(q)
phase_to_u1.u1(theta, 0)
phase_to_u1.append(U1Gate(theta), [0])
_sel.add_equivalence(PhaseGate(theta), phase_to_u1)

q = QuantumRegister(1, 'q')
theta = Parameter('theta')
phase_to_u = QuantumCircuit(q)
phase_to_u.u(0, 0, theta, 0)
_sel.add_equivalence(PhaseGate(theta), phase_to_u)

# CPhaseGate

q = QuantumRegister(2, 'q')
Expand All @@ -130,7 +136,7 @@
q = QuantumRegister(2, 'q')
theta = Parameter('theta')
cphase_to_cu1 = QuantumCircuit(q)
cphase_to_cu1.cu1(theta, 0, 1)
cphase_to_cu1.append(CU1Gate(theta), [0, 1])
_sel.add_equivalence(CPhaseGate(theta), cphase_to_cu1)

# RGate
Expand Down Expand Up @@ -440,7 +446,7 @@
phi = Parameter('phi')
lam = Parameter('lam')
u_to_u3 = QuantumCircuit(q)
u_to_u3.u3(theta, phi, lam, 0)
u_to_u3.append(U3Gate(theta, phi, lam), [0])
_sel.add_equivalence(UGate(theta, phi, lam), u_to_u3)

# CUGate
Expand All @@ -467,7 +473,7 @@
gamma = Parameter('gamma')
cu_to_cu3 = QuantumCircuit(q)
cu_to_cu3.p(gamma, 0)
cu_to_cu3.cu3(theta, phi, lam, 0, 1)
cu_to_cu3.append(CU3Gate(theta, phi, lam), [0, 1])
_sel.add_equivalence(CUGate(theta, phi, lam, gamma), cu_to_cu3)

# U1Gate
Expand Down Expand Up @@ -514,9 +520,9 @@
phi = Parameter('phi')
lam = Parameter('lam')
u2_to_u1sx = QuantumCircuit(q, global_phase=-pi / 4)
u2_to_u1sx.u1(lam - pi/2, 0)
u2_to_u1sx.append(U1Gate(lam - pi/2), [0])
u2_to_u1sx.sx(0)
u2_to_u1sx.u1(phi + pi/2, 0)
u2_to_u1sx.append(U1Gate(phi + pi/2), [0])
_sel.add_equivalence(U2Gate(phi, lam), u2_to_u1sx)

# U3Gate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@
logger = logging.getLogger(__name__)


def _apply_cu3(circuit, theta, phi, lam, control, target, use_basis_gates=True):
def _apply_cu(circuit, theta, phi, lam, control, target, use_basis_gates=True):
if use_basis_gates:
circuit.u1((lam + phi) / 2, control)
circuit.u1((lam - phi) / 2, target)
# pylint: disable=cyclic-import
circuit.p((lam + phi) / 2, [control])
circuit.p((lam - phi) / 2, [target])
circuit.cx(control, target)
circuit.u3(-theta / 2, 0, -(phi + lam) / 2, target)
circuit.u(-theta / 2, 0, -(phi + lam) / 2, [target])
circuit.cx(control, target)
circuit.u3(theta / 2, phi, 0, target)
circuit.u(theta / 2, phi, 0, [target])
else:
circuit.cu(theta, phi, lam, 0, control, target)


def _apply_mcu3_graycode(circuit, theta, phi, lam, ctls, tgt, use_basis_gates):
"""Apply multi-controlled u3 gate from ctls to tgt using graycode
def _apply_mcu_graycode(circuit, theta, phi, lam, ctls, tgt, use_basis_gates):
"""Apply multi-controlled u gate from ctls to tgt using graycode
pattern with single-step angles theta, phi, lam."""

n = len(ctls)
Expand Down Expand Up @@ -67,12 +68,12 @@ def _apply_mcu3_graycode(circuit, theta, phi, lam, ctls, tgt, use_basis_gates):
circuit.cx(ctls[idx], ctls[lm_pos])
# check parity and undo rotation
if pattern.count('1') % 2 == 0:
# inverse CU3: u3(theta, phi, lamb)^dagger = u3(-theta, -lam, -phi)
_apply_cu3(circuit, -theta, -lam, -phi, ctls[lm_pos], tgt,
use_basis_gates=use_basis_gates)
# inverse CU: u(theta, phi, lamb)^dagger = u(-theta, -lam, -phi)
_apply_cu(circuit, -theta, -lam, -phi, ctls[lm_pos], tgt,
use_basis_gates=use_basis_gates)
else:
_apply_cu3(circuit, theta, phi, lam, ctls[lm_pos], tgt,
use_basis_gates=use_basis_gates)
_apply_cu(circuit, theta, phi, lam, ctls[lm_pos], tgt,
use_basis_gates=use_basis_gates)
last_pattern = pattern


Expand All @@ -85,7 +86,7 @@ def mcrx(self, theta, q_controls, q_target, use_basis_gates=False):
theta (float): angle theta
q_controls (list(Qubit)): The list of control qubits
q_target (Qubit): The target qubit
use_basis_gates (bool): use u1, u2, u3, cx, id
use_basis_gates (bool): use p, u, cx

Raises:
QiskitError: parameter errors
Expand All @@ -112,13 +113,13 @@ def mcrx(self, theta, q_controls, q_target, use_basis_gates=False):
self._check_dups(all_qubits)

n_c = len(control_qubits)
if n_c == 1: # cu3
_apply_cu3(self, theta, -pi/2, pi/2, control_qubits[0],
target_qubit, use_basis_gates=use_basis_gates)
if n_c == 1: # cu
_apply_cu(self, theta, -pi/2, pi/2, control_qubits[0],
target_qubit, use_basis_gates=use_basis_gates)
else:
theta_step = theta * (1 / (2 ** (n_c - 1)))
_apply_mcu3_graycode(self, theta_step, -pi/2, pi/2, control_qubits,
target_qubit, use_basis_gates=use_basis_gates)
_apply_mcu_graycode(self, theta_step, -pi/2, pi/2, control_qubits,
target_qubit, use_basis_gates=use_basis_gates)


def mcry(self, theta, q_controls, q_target, q_ancillae, mode=None,
Expand All @@ -133,7 +134,7 @@ def mcry(self, theta, q_controls, q_target, q_ancillae, mode=None,
q_target (Qubit): The target qubit
q_ancillae (QuantumRegister or tuple(QuantumRegister, int)): The list of ancillary qubits.
mode (string): The implementation mode to use
use_basis_gates (bool): use u1, u2, u3, cx, id
use_basis_gates (bool): use p, u, cx

Raises:
QiskitError: parameter errors
Expand Down Expand Up @@ -186,13 +187,13 @@ def mcry(self, theta, q_controls, q_target, q_ancillae, mode=None,
self.mcx(q_controls, q_target, q_ancillae, mode='v-chain')
elif mode == 'noancilla':
n_c = len(control_qubits)
if n_c == 1: # cu3
_apply_cu3(self, theta, 0, 0, control_qubits[0],
target_qubit, use_basis_gates=use_basis_gates)
if n_c == 1: # cu
_apply_cu(self, theta, 0, 0, control_qubits[0],
target_qubit, use_basis_gates=use_basis_gates)
else:
theta_step = theta * (1 / (2 ** (n_c - 1)))
_apply_mcu3_graycode(self, theta_step, 0, 0, control_qubits,
target_qubit, use_basis_gates=use_basis_gates)
_apply_mcu_graycode(self, theta_step, 0, 0, control_qubits,
target_qubit, use_basis_gates=use_basis_gates)
else:
raise QiskitError('Unrecognized mode for building MCRY circuit: {}.'.format(mode))

Expand All @@ -206,7 +207,7 @@ def mcrz(self, lam, q_controls, q_target, use_basis_gates=False):
lam (float): angle lambda
q_controls (list(Qubit)): The list of control qubits
q_target (Qubit): The target qubit
use_basis_gates (bool): use u1, u2, u3, cx, id
use_basis_gates (bool): use p, u, cx

Raises:
QiskitError: parameter errors
Expand All @@ -233,13 +234,13 @@ def mcrz(self, lam, q_controls, q_target, use_basis_gates=False):
self._check_dups(all_qubits)

n_c = len(control_qubits)
if n_c == 1: # cu3
_apply_cu3(self, 0, 0, lam, control_qubits[0],
target_qubit, use_basis_gates=use_basis_gates)
if n_c == 1: # cu
_apply_cu(self, 0, 0, lam, control_qubits[0],
target_qubit, use_basis_gates=use_basis_gates)
else:
lam_step = lam * (1 / (2 ** (n_c - 1)))
_apply_mcu3_graycode(self, 0, 0, lam_step, control_qubits,
target_qubit, use_basis_gates=use_basis_gates)
_apply_mcu_graycode(self, 0, 0, lam_step, control_qubits,
target_qubit, use_basis_gates=use_basis_gates)


QuantumCircuit.mcrx = mcrx
Expand Down
3 changes: 2 additions & 1 deletion qiskit/circuit/library/standard_gates/p.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ def __init__(self, theta, label=None):
def _define(self):
# pylint: disable=cyclic-import
from qiskit.circuit.quantumcircuit import QuantumCircuit
from .u import UGate
q = QuantumRegister(1, 'q')
qc = QuantumCircuit(q, name=self.name)
qc.u1(self.params[0], 0)
qc.append(UGate(0, 0, self.params[0]), [0])
self.definition = qc

def control(self, num_ctrl_qubits=1, label=None, ctrl_state=None):
Expand Down
8 changes: 0 additions & 8 deletions qiskit/circuit/library/standard_gates/u.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ def control(self, num_ctrl_qubits=1, label=None, ctrl_state=None):
return gate
return super().control(num_ctrl_qubits=num_ctrl_qubits, label=label, ctrl_state=ctrl_state)

def _define(self):
"""Alias for U3 until U becomes a basis gate."""
from qiskit.circuit.quantumcircuit import QuantumCircuit
q = QuantumRegister(1, 'q')
qc = QuantumCircuit(q)
qc.u3(self.params[0], self.params[1], self.params[2], q[0])
self.definition = qc

def to_matrix(self):
"""Return a numpy.array for the U gate."""
theta, phi, lam = [float(param) for param in self.params]
Expand Down
Loading