Skip to content

Commit

Permalink
Merge branch 'main' into add-py311-support
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish authored Nov 2, 2022
2 parents 0be2e8e + b0f3d5c commit 8044296
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 573 deletions.
2 changes: 1 addition & 1 deletion examples/python/rippleadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def unmajority(p, a, b, c):
qc.x(a[0]) # Set input a = 0...0001
qc.x(b) # Set input b = 1...1111
# Apply the adder
qc += adder_subcircuit
qc &= adder_subcircuit
# Measure the output register in the computational basis
for j in range(n):
qc.measure(b[j], ans[j])
Expand Down
326 changes: 0 additions & 326 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from qiskit.qasm.qasm import Qasm
from qiskit.qasm.exceptions import QasmError
from qiskit.circuit.exceptions import CircuitError
from qiskit.utils.deprecation import deprecate_function
from .parameterexpression import ParameterExpression, ParameterValueType
from .quantumregister import QuantumRegister, Qubit, AncillaRegister, AncillaQubit
from .classicalregister import ClassicalRegister, Clbit
Expand Down Expand Up @@ -753,109 +752,6 @@ def control(

return controlled_circ

@deprecate_function(
"The QuantumCircuit.combine() method is being deprecated. "
"Use the compose() method which is more flexible w.r.t "
"circuit register compatibility."
)
def combine(self, rhs: "QuantumCircuit") -> "QuantumCircuit":
"""DEPRECATED - Returns rhs appended to self if self contains compatible registers.
Two circuits are compatible if they contain the same registers
or if they contain different registers with unique names. The
returned circuit will contain all unique registers between both
circuits.
Return self + rhs as a new object.
Args:
rhs (QuantumCircuit): The quantum circuit to append to the right hand side.
Returns:
QuantumCircuit: Returns a new QuantumCircuit object
Raises:
QiskitError: if the rhs circuit is not compatible
"""
# Check registers in LHS are compatible with RHS
self._check_compatible_regs(rhs)

# Make new circuit with combined registers
combined_qregs = copy.deepcopy(self.qregs)
combined_cregs = copy.deepcopy(self.cregs)

for element in rhs.qregs:
if element not in self.qregs:
combined_qregs.append(element)
for element in rhs.cregs:
if element not in self.cregs:
combined_cregs.append(element)
circuit = QuantumCircuit(*combined_qregs, *combined_cregs)
for instruction in itertools.chain(self.data, rhs.data):
circuit._append(instruction)
circuit.global_phase = self.global_phase + rhs.global_phase

for gate, cals in rhs.calibrations.items():
for key, sched in cals.items():
circuit.add_calibration(gate, qubits=key[0], schedule=sched, params=key[1])

for gate, cals in self.calibrations.items():
for key, sched in cals.items():
circuit.add_calibration(gate, qubits=key[0], schedule=sched, params=key[1])

return circuit

@deprecate_function(
"The QuantumCircuit.extend() method is being deprecated. Use the "
"compose() (potentially with the inplace=True argument) and tensor() "
"methods which are more flexible w.r.t circuit register compatibility."
)
def extend(self, rhs: "QuantumCircuit") -> "QuantumCircuit":
"""DEPRECATED - Append QuantumCircuit to the RHS if it contains compatible registers.
Two circuits are compatible if they contain the same registers
or if they contain different registers with unique names. The
returned circuit will contain all unique registers between both
circuits.
Modify and return self.
Args:
rhs (QuantumCircuit): The quantum circuit to append to the right hand side.
Returns:
QuantumCircuit: Returns this QuantumCircuit object (which has been modified)
Raises:
QiskitError: if the rhs circuit is not compatible
"""
# Check registers in LHS are compatible with RHS
self._check_compatible_regs(rhs)

# Add new registers
for element in rhs.qregs:
if element not in self.qregs:
self.add_register(element)

for element in rhs.cregs:
if element not in self.cregs:
self.add_register(element)

# Copy the circuit data if rhs and self are the same, otherwise the data of rhs is
# appended to both self and rhs resulting in an infinite loop
data = rhs.data.copy() if rhs is self else rhs.data

# Add new gates
for instruction in data:
self._append(instruction)
self.global_phase += rhs.global_phase

for gate, cals in rhs.calibrations.items():
for key, sched in cals.items():
self.add_calibration(gate, qubits=key[0], schedule=sched, params=key[1])

return self

def compose(
self,
other: Union["QuantumCircuit", Instruction],
Expand Down Expand Up @@ -1146,24 +1042,6 @@ def ancillas(self) -> List[AncillaQubit]:
"""
return self._ancillas

@deprecate_function(
"The QuantumCircuit.__add__() method is being deprecated."
"Use the compose() method which is more flexible w.r.t "
"circuit register compatibility."
)
def __add__(self, rhs: "QuantumCircuit") -> "QuantumCircuit":
"""Overload + to implement self.combine."""
return self.combine(rhs)

@deprecate_function(
"The QuantumCircuit.__iadd__() method is being deprecated. Use the "
"compose() (potentially with the inplace=True argument) and tensor() "
"methods which are more flexible w.r.t circuit register compatibility."
)
def __iadd__(self, rhs: "QuantumCircuit") -> "QuantumCircuit":
"""Overload += to implement self.extend."""
return self.extend(rhs)

def __and__(self, rhs: "QuantumCircuit") -> "QuantumCircuit":
"""Overload & to implement self.compose."""
return self.compose(rhs)
Expand Down Expand Up @@ -1652,19 +1530,6 @@ def decompose(
dag = pass_.run(dag)
return dag_to_circuit(dag)

def _check_compatible_regs(self, rhs: "QuantumCircuit") -> None:
"""Raise exception if the circuits are defined on incompatible registers"""
list1 = self.qregs + self.cregs
list2 = rhs.qregs + rhs.cregs
for element1 in list1:
for element2 in list2:
if element2.name == element1.name:
if element1 != element2:
raise CircuitError(
"circuits are not compatible:"
f" registers {element1} and {element2} not compatible"
)

def _unique_register_name(self, prefix: str = "") -> str:
"""Generate a register name with the given prefix, which is unique within this circuit."""
used = {
Expand Down Expand Up @@ -3800,197 +3665,6 @@ def cu(
[],
)

@deprecate_function(
"The QuantumCircuit.u1 method is deprecated as of "
"0.16.0. It will be removed no earlier than 3 months "
"after the release date. You should use the "
"QuantumCircuit.p method instead, which acts "
"identically."
)
def u1(self, theta: ParameterValueType, qubit: QubitSpecifier) -> InstructionSet:
r"""Apply :class:`~qiskit.circuit.library.U1Gate`.
For the full matrix form of this gate, see the underlying gate documentation.
Args:
theta: The :math:`\theta` rotation angle of the gate.
qubit: The qubit(s) to apply the gate to.
Returns:
A handle to the instructions created.
"""
from .library.standard_gates.u1 import U1Gate

return self.append(U1Gate(theta), [qubit], [])

@deprecate_function(
"The QuantumCircuit.cu1 method is deprecated as of "
"0.16.0. It will be removed no earlier than 3 months "
"after the release date. You should use the "
"QuantumCircuit.cp method instead, which acts "
"identically."
)
def cu1(
self,
theta: ParameterValueType,
control_qubit: QubitSpecifier,
target_qubit: QubitSpecifier,
label: Optional[str] = None,
ctrl_state: Optional[Union[str, int]] = None,
) -> InstructionSet:
r"""Apply :class:`~qiskit.circuit.library.CU1Gate`.
For the full matrix form of this gate, see the underlying gate documentation.
Args:
theta: The :math:`\theta` rotation angle of the gate.
control_qubit: The qubit(s) used as the control.
target_qubit: The qubit(s) targeted by the gate.
label: The string label of the gate in the circuit.
ctrl_state:
The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling
on the '1' state.
Returns:
A handle to the instructions created.
"""
from .library.standard_gates.u1 import CU1Gate

return self.append(
CU1Gate(theta, label=label, ctrl_state=ctrl_state), [control_qubit, target_qubit], []
)

@deprecate_function(
"The QuantumCircuit.mcu1 method is deprecated as of "
"0.16.0. It will be removed no earlier than 3 months "
"after the release date. You should use the "
"QuantumCircuit.mcp method instead, which acts "
"identically."
)
def mcu1(
self,
lam: ParameterValueType,
control_qubits: Sequence[QubitSpecifier],
target_qubit: QubitSpecifier,
) -> InstructionSet:
r"""Apply :class:`~qiskit.circuit.library.MCU1Gate`.
For the full matrix form of this gate, see the underlying gate documentation.
Args:
lam: The :math:`\lambda` rotation angle of the gate.
control_qubits: The qubits used as the controls.
target_qubit: The qubit(s) targeted by the gate.
Returns:
A handle to the instructions created.
"""
from .library.standard_gates.u1 import MCU1Gate

num_ctrl_qubits = len(control_qubits)
return self.append(MCU1Gate(lam, num_ctrl_qubits), control_qubits[:] + [target_qubit], [])

@deprecate_function(
"The QuantumCircuit.u2 method is deprecated as of "
"0.16.0. It will be removed no earlier than 3 months "
"after the release date. You can use the general 1-"
"qubit gate QuantumCircuit.u instead: u2(φ,λ) = "
"u(π/2, φ, λ). Alternatively, you can decompose it in"
"terms of QuantumCircuit.p and QuantumCircuit.sx: "
"u2(φ,λ) = p(π/2+φ) sx p(λ-π/2) (1 pulse on hardware)."
)
def u2(
self, phi: ParameterValueType, lam: ParameterValueType, qubit: QubitSpecifier
) -> InstructionSet:
r"""Apply :class:`~qiskit.circuit.library.U2Gate`.
For the full matrix form of this gate, see the underlying gate documentation.
Args:
phi: The :math:`\phi` rotation angle of the gate.
lam: The :math:`\lambda` rotation angle of the gate.
qubit: The qubit(s) to apply the gate to.
Returns:
A handle to the instructions created.
"""
from .library.standard_gates.u2 import U2Gate

return self.append(U2Gate(phi, lam), [qubit], [])

@deprecate_function(
"The QuantumCircuit.u3 method is deprecated as of 0.16.0. It will be "
"removed no earlier than 3 months after the release date. You should use "
"QuantumCircuit.u instead, which acts identically. Alternatively, you can "
"decompose u3 in terms of QuantumCircuit.p and QuantumCircuit.sx: "
"u3(ϴ,φ,λ) = p(φ+π) sx p(ϴ+π) sx p(λ) (2 pulses on hardware)."
)
def u3(
self,
theta: ParameterValueType,
phi: ParameterValueType,
lam: ParameterValueType,
qubit: QubitSpecifier,
) -> InstructionSet:
r"""Apply :class:`~qiskit.circuit.library.U3Gate`.
For the full matrix form of this gate, see the underlying gate documentation.
Args:
theta: The :math:`\theta` rotation angle of the gate.
phi: The :math:`\phi` rotation angle of the gate.
lam: The :math:`\lambda` rotation angle of the gate.
qubit: The qubit(s) to apply the gate to.
Returns:
A handle to the instructions created.
"""
from .library.standard_gates.u3 import U3Gate

return self.append(U3Gate(theta, phi, lam), [qubit], [])

@deprecate_function(
"The QuantumCircuit.cu3 method is deprecated as of 0.16.0. It will be "
"removed no earlier than 3 months after the release date. You should "
"use the QuantumCircuit.cu method instead, where "
"cu3(ϴ,φ,λ) = cu(ϴ,φ,λ,0)."
)
def cu3(
self,
theta: ParameterValueType,
phi: ParameterValueType,
lam: ParameterValueType,
control_qubit: QubitSpecifier,
target_qubit: QubitSpecifier,
label: Optional[str] = None,
ctrl_state: Optional[Union[str, int]] = None,
) -> InstructionSet:
r"""Apply :class:`~qiskit.circuit.library.CU3Gate`.
For the full matrix form of this gate, see the underlying gate documentation.
Args:
theta: The :math:`\theta` rotation angle of the gate.
phi: The :math:`\phi` rotation angle of the gate.
lam: The :math:`\lambda` rotation angle of the gate.
control_qubit: The qubit(s) used as the control.
target_qubit: The qubit(s) targeted by the gate.
label: The string label of the gate in the circuit.
ctrl_state:
The control state in decimal, or as a bitstring (e.g. '1'). Defaults to controlling
on the '1' state.
Returns:
A handle to the instructions created.
"""
from .library.standard_gates.u3 import CU3Gate

return self.append(
CU3Gate(theta, phi, lam, label=label, ctrl_state=ctrl_state),
[control_qubit, target_qubit],
[],
)

def x(self, qubit: QubitSpecifier, label: Optional[str] = None) -> InstructionSet:
r"""Apply :class:`~qiskit.circuit.library.XGate`.
Expand Down
7 changes: 0 additions & 7 deletions qiskit/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,10 @@ def setUpClass(cls):
for mod in allow_DeprecationWarning_modules:
warnings.filterwarnings("default", category=DeprecationWarning, module=mod)
allow_DeprecationWarning_message = [
r".*QuantumCircuit\.combine.*",
r".*QuantumCircuit\.__add__.*",
r".*QuantumCircuit\.__iadd__.*",
r".*QuantumCircuit\.extend.*",
r".*qiskit\.circuit\.library\.standard_gates\.ms import.*",
r"elementwise comparison failed.*",
r"The jsonschema validation included in qiskit-terra.*",
r"The DerivativeBase.parameter_expression_grad method.*",
r"Back-references to from Bit instances.*",
r"The QuantumCircuit.u. method.*",
r"The QuantumCircuit.cu.",
r"The CXDirection pass has been deprecated",
r"The pauli_basis function with PauliTable.*",
# TODO: remove the following ignore after seaborn 0.12.0 releases
Expand Down
2 changes: 1 addition & 1 deletion qiskit/transpiler/synthesis/graysynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def graysynth(cnots, angles, section_size=2):
else:
sta.append([cnots1, list(set(ilist).difference([j])), qubit])
sta.append([cnots0, list(set(ilist).difference([j])), qubit])
qcir += cnot_synth(state, section_size).inverse()
qcir &= cnot_synth(state, section_size).inverse()
return qcir


Expand Down
Loading

0 comments on commit 8044296

Please sign in to comment.