Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 0 additions & 67 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/apidocs/terra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ Qiskit Terra API Reference
transpiler_preset
transpiler_plugins
utils
utils_mitigation
opflow
algorithms
6 changes: 6 additions & 0 deletions docs/apidocs/utils_mitigation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _qiskit-utils-mitigation:

.. automodule:: qiskit.utils.mitigation
:no-members:
:no-inherited-members:
:no-special-members:
72 changes: 72 additions & 0 deletions examples/python/circuit_element_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from qiskit.circuit import QuantumRegister, QuantumCircuit
from qiskit.quantum_info.operators.symplectic import Clifford
from qiskit import transpile

# This example runs through to the end
def experiment1():
# create a new clifford (from a circuit)
qc = QuantumCircuit(3)
qc.s(0)
qc.cx(0, 1)
qc.h(1)
print(qc)
cliff = Clifford(qc)
print(cliff)
print(f"Created cliff of type {type(cliff)}")

# append our clifford to another circuit
q2 = QuantumRegister(5, "q")
qc2 = QuantumCircuit(q2)
qc2.h(0)
qc2.h(1)
qc2.barrier()
qc2.append(cliff, [q2[0], q2[1], q2[4]], [])
qc2.barrier()
qc2.cx(3, 4)

# draw the circuit (with our clifford inside)
print(qc2)

# decompose the circuit
# (and only now decomposing our clifford)
qc3 = qc2.decompose()

# draw the decomposed circuit
print(qc3)


# This example is still not fully working
def experiment2():
# create a new clifford (from a circuit)
qc = QuantumCircuit(3)
qc.s(0)
qc.cx(0, 1)
qc.h(1)
print(qc)
cliff = Clifford(qc)
print(cliff)
print(f"Created cliff of type {type(cliff)}")

# append our clifford to another circuit
q2 = QuantumRegister(5, "q")
qc2 = QuantumCircuit(q2)
qc2.h(0)
qc2.h(1)
qc2.barrier()
qc2.append(cliff, [q2[0], q2[1], q2[4]], [])
qc2.barrier()
qc2.cx(3, 4)

# draw the circuit (with our clifford inside)
print(qc2)

# transpile the circuit (work-in-progress)
# (and only now decomposing our clifford)
qc3 = transpile(qc2, basis_gates={'rz', 'x', 'sx', 'cx'})

# draw the decomposed circuit
print(qc3)


# main
experiment1()
1 change: 1 addition & 0 deletions qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
from .controlledgate import ControlledGate
from .instruction import Instruction
from .instructionset import InstructionSet
from .circuit_element import CircuitElement
from .barrier import Barrier
from .delay import Delay
from .measure import Measure
Expand Down
3 changes: 2 additions & 1 deletion qiskit/circuit/instructionset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from qiskit.circuit.exceptions import CircuitError
from .instruction import Instruction
from .classicalregister import Clbit
from .circuit_element import CircuitElement


class InstructionSet:
Expand Down Expand Up @@ -46,7 +47,7 @@ def __getitem__(self, i):

def add(self, gate, qargs, cargs):
"""Add an instruction and its context (where it is attached)."""
if not isinstance(gate, Instruction):
if not isinstance(gate, CircuitElement):
raise CircuitError("attempt to add non-Instruction" + " to InstructionSet")
self.instructions.append(gate)
self.qargs.append(qargs)
Expand Down
5 changes: 2 additions & 3 deletions qiskit/circuit/library/basis_change/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ def num_qubits(self, num_qubits: int) -> None:
if num_qubits != self.num_qubits:
self._invalidate()

if num_qubits:
self.qregs = []
if num_qubits is not None and num_qubits > 0:
self.qregs = [QuantumRegister(num_qubits, name="q")]
else:
self.qregs = []

@property
def approximation_degree(self) -> int:
Expand Down
49 changes: 30 additions & 19 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from .delay import Delay
from .measure import Measure
from .reset import Reset
from .circuit_element import CircuitElement

try:
import pygments
Expand Down Expand Up @@ -863,16 +864,14 @@ def compose(
mapped_instrs.append((n_instr, n_qargs, n_cargs))

if front:
# adjust new instrs before original ones and update all parameters
dest._data = mapped_instrs + dest._data
else:
dest._data += mapped_instrs

if front:
dest._parameter_table.clear()
for instr, _, _ in dest._data:
dest._update_parameter_table(instr)
else:
# just append new parameters
# just append new instrs and parameters
dest._data += mapped_instrs
for instr, _, _ in mapped_instrs:
dest._update_parameter_table(instr)

Expand Down Expand Up @@ -1124,7 +1123,7 @@ def cbit_argument_conversion(self, clbit_representation: ClbitSpecifier) -> List

def append(
self,
instruction: Instruction,
instruction: CircuitElement,
qargs: Optional[Sequence[QubitSpecifier]] = None,
cargs: Optional[Sequence[ClbitSpecifier]] = None,
) -> InstructionSet:
Expand All @@ -1144,18 +1143,30 @@ def append(
CircuitError: if object passed is neither subclass nor an instance of Instruction
"""
# Convert input to instruction
if not isinstance(instruction, Instruction) and not hasattr(instruction, "to_instruction"):
if issubclass(instruction, Instruction):

#
#

# New behavior: for CircuitElements we do *not* call to_instruction()
if isinstance(instruction, CircuitElement):
pass

# Old behavior (to sunset): on this very first pass, QuantumCircuit (and possibly some other classes)
# do not yet inherit from CircuitElement. For example, we still need to call to_instruction() to append
# one QuantumCircuit to another.
else:
if not isinstance(instruction, Instruction) and not hasattr(instruction, "to_instruction"):
if issubclass(instruction, Instruction):
raise CircuitError(
"Object is a subclass of Instruction, please add () to "
"pass an instance of this object."
)

raise CircuitError(
"Object is a subclass of Instruction, please add () to "
"pass an instance of this object."
"Object to append must be an Instruction or have a to_instruction() method."
)

raise CircuitError(
"Object to append must be an Instruction or have a to_instruction() method."
)
if not isinstance(instruction, Instruction) and hasattr(instruction, "to_instruction"):
instruction = instruction.to_instruction()
if not isinstance(instruction, Instruction) and hasattr(instruction, "to_instruction"):
instruction = instruction.to_instruction()

# Make copy of parameterized gate instances
if hasattr(instruction, "params"):
Expand All @@ -1172,7 +1183,7 @@ def append(
return instructions

def _append(
self, instruction: Instruction, qargs: Sequence[Qubit], cargs: Sequence[Clbit]
self, instruction: CircuitElement, qargs: Sequence[Qubit], cargs: Sequence[Clbit]
) -> Instruction:
"""Append an instruction to the end of the circuit, modifying
the circuit in place.
Expand All @@ -1189,8 +1200,8 @@ def _append(
CircuitError: if the gate is of a different shape than the wires
it is being attached to.
"""
if not isinstance(instruction, Instruction):
raise CircuitError("object is not an Instruction.")
if not isinstance(instruction, CircuitElement):
raise CircuitError("object is not a CircuitElement.")

# do some compatibility checks
self._check_dups(qargs)
Expand Down
2 changes: 1 addition & 1 deletion qiskit/extensions/quantum_initializer/squ.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, unitary_matrix, mode="ZYZ", up_to_diagonal=False, u=None):
self._diag = None

# Create new gate
super().__init__("unitary", 1, [unitary_matrix])
super().__init__("squ", 1, [unitary_matrix])

def inverse(self):
"""Return the inverse.
Expand Down
Loading