Skip to content

Commit

Permalink
Merge branch 'main' into main_shelly_qft
Browse files Browse the repository at this point in the history
  • Loading branch information
ShellyGarion committed Nov 19, 2023
2 parents f2248dd + 1dd4f54 commit a88d66a
Show file tree
Hide file tree
Showing 98 changed files with 634 additions and 243 deletions.
3 changes: 3 additions & 0 deletions .azure/lint-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ jobs:
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt \
./qiskit_pkg \
-e .
# Build and install both qiskit and qiskit-terra so that any optionals
# depending on `qiskit` will resolve correctly.
displayName: 'Install dependencies'
env:
SETUPTOOLS_ENABLE_FEATURES: "legacy-editable"
Expand Down
15 changes: 10 additions & 5 deletions .azure/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ jobs:
# Use stable Rust, rather than MSRV, to spot-check that stable builds properly.
rustup override set stable
source test-job/bin/activate
python -m pip install -U pip setuptools wheel
# Install setuptools-rust for building sdist
python -m pip install -U -c constraints.txt setuptools-rust
python setup.py sdist
python -m pip install -U pip
python -m pip install -U build
python -m build --sdist .
python -m build --sdist qiskit_pkg
python -m pip install -U \
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt \
dist/qiskit-terra*.tar.gz
dist/qiskit*.tar.gz
# Build and install both qiskit and qiskit-terra so that any optionals
# depending on `qiskit` will resolve correctly.
displayName: "Install Terra from sdist"
- ${{ if eq(parameters.installFromSdist, false) }}:
Expand All @@ -90,7 +92,10 @@ jobs:
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt \
./qiskit_pkg \
-e .
# Build and install both qiskit and qiskit-terra so that any optionals
# depending on `qiskit` will resolve correctly.
displayName: "Install Terra directly"
env:
SETUPTOOLS_ENABLE_FEATURES: "legacy-editable"
Expand Down
3 changes: 3 additions & 0 deletions .azure/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ jobs:
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt \
./qiskit_pkg \
-e .
# Build and install both qiskit and qiskit-terra so that any optionals
# depending on `qiskit` will resolve correctly.
pip check
displayName: 'Install dependencies'
env:
Expand Down
3 changes: 3 additions & 0 deletions .azure/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ jobs:
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt \
./qiskit_pkg \
-e .
# Build and install both qiskit and qiskit-terra so that any optionals
# depending on `qiskit` will resolve correctly.
pip check
displayName: 'Install dependencies'
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: python -m pip install -c constraints.txt --upgrade pip setuptools wheel

- name: Build and install qiskit-terra
run: python -m pip install -c constraints.txt -e .
run: python -m pip install -c constraints.txt -e . ./qiskit_pkg
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-Cinstrument-coverage"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/slow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
python -m pip install -U pip setuptools wheel
python -m pip install -U -r requirements.txt -c constraints.txt
python -m pip install -U -r requirements-dev.txt -c constraints.txt
python -m pip install -c constraints.txt -e .
python -m pip install -c constraints.txt -e . ./qiskit_pkg
python -m pip install "qiskit-aer" "z3-solver" "cplex" -c constraints.txt
env:
SETUPTOOLS_ENABLE_FEATURES: "legacy-editable"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ qc_example.cx(0,1) # 0th-qubit-Controlled-NOT gate on 1st qubit
qc_example.cx(0,2) # 0th-qubit-Controlled-NOT gate on 2nd qubit
```

This simple example makes an entangled state known as a [GHZ state](https://en.wikipedia.org/wiki/Greenberger%E2%80%93Horne%E2%80%93Zeilinger_state) $(|000\rangle + |111\rangle)/\sqrt{2}$. It uses the standard quantum gates: Hadamard gate (`h`), Phase gate (`p`), and CNOT gate (`cx`).
This simple example makes an entangled state known as a [GHZ state](https://en.wikipedia.org/wiki/Greenberger%E2%80%93Horne%E2%80%93Zeilinger_state) $(|000\rangle + i|111\rangle)/\sqrt{2}$. It uses the standard quantum gates: Hadamard gate (`h`), Phase gate (`p`), and CNOT gate (`cx`).

Once you've made your first quantum circuit, choose which primitive function you will use. Starting with `sampler`,
we use `measure_all(inplace=False)` to get a copy of the circuit in which all the qubits are measured:
Expand Down
4 changes: 1 addition & 3 deletions qiskit/circuit/library/generalized_gates/unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def __eq__(self, other):
return False
if self.label != other.label:
return False
# Should we match unitaries as equal if they are equal
# up to global phase?
return matrix_equal(self.params[0], other.params[0], ignore_phase=True)
return matrix_equal(self.params[0], other.params[0])

def __array__(self, dtype=None):
"""Return matrix for the unitary."""
Expand Down
6 changes: 4 additions & 2 deletions qiskit/circuit/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
Quantum measurement in the computational basis.
"""

from qiskit.circuit.instruction import Instruction
from qiskit.circuit.singleton import SingletonInstruction, stdlib_singleton_key
from qiskit.circuit.exceptions import CircuitError


class Measure(Instruction):
class Measure(SingletonInstruction):
"""Quantum measurement in the computational basis."""

def __init__(self, label=None, *, duration=None, unit="dt"):
"""Create new measurement instruction."""
super().__init__("measure", 1, 1, [], label=label, duration=duration, unit=unit)

_singleton_lookup_key = stdlib_singleton_key()

def broadcast_arguments(self, qargs, cargs):
qarg = qargs[0]
carg = cargs[0]
Expand Down
29 changes: 10 additions & 19 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
from .bit import Bit
from .quantumcircuitdata import QuantumCircuitData, CircuitInstruction
from .delay import Delay
from .measure import Measure
from .reset import Reset

if typing.TYPE_CHECKING:
import qiskit # pylint: disable=cyclic-import
Expand Down Expand Up @@ -2180,6 +2178,8 @@ def reset(self, qubit: QubitSpecifier) -> InstructionSet:
Returns:
qiskit.circuit.InstructionSet: handle to the added instruction.
"""
from .reset import Reset

return self.append(Reset(), [qubit], [])

def measure(self, qubit: QubitSpecifier, cbit: ClbitSpecifier) -> InstructionSet:
Expand Down Expand Up @@ -2255,6 +2255,8 @@ def measure(self, qubit: QubitSpecifier, cbit: ClbitSpecifier) -> InstructionSet
circuit.measure(qreg[1], creg[1])
"""
from .measure import Measure

return self.append(Measure(), [qubit], [cbit])

def measure_active(self, inplace: bool = True) -> Optional["QuantumCircuit"]:
Expand Down Expand Up @@ -2850,23 +2852,12 @@ def barrier(self, *qargs: QubitSpecifier, label=None) -> InstructionSet:
"""
from .barrier import Barrier

qubits: list[QubitSpecifier] = []

if not qargs: # None
qubits.extend(self.qubits)

for qarg in qargs:
if isinstance(qarg, QuantumRegister):
qubits.extend([qarg[j] for j in range(qarg.size)])
elif isinstance(qarg, list):
qubits.extend(qarg)
elif isinstance(qarg, range):
qubits.extend(list(qarg))
elif isinstance(qarg, slice):
qubits.extend(self.qubits[qarg])
else:
qubits.append(qarg)

qubits = (
# This uses a `dict` not a `set` to guarantee a deterministic order to the arguments.
list({q: None for qarg in qargs for q in self.qbit_argument_conversion(qarg)})
if qargs
else self.qubits.copy()
)
return self.append(Barrier(len(qubits), label=label), qubits, [])

def delay(
Expand Down
6 changes: 4 additions & 2 deletions qiskit/circuit/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
Qubit reset to computational zero.
"""

from qiskit.circuit.instruction import Instruction
from qiskit.circuit.singleton import SingletonInstruction, stdlib_singleton_key


class Reset(Instruction):
class Reset(SingletonInstruction):
"""Qubit reset."""

def __init__(self, label=None, *, duration=None, unit="dt"):
"""Create new reset instruction."""
super().__init__("reset", 1, 0, [], label=label, duration=duration, unit=unit)

_singleton_lookup_key = stdlib_singleton_key()

def broadcast_arguments(self, qargs, cargs):
for qarg in qargs[0]:
yield [qarg], []
4 changes: 2 additions & 2 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from qiskit.pulse import Schedule, InstructionScheduleMap
from qiskit.transpiler import Layout, CouplingMap, PropertySet
from qiskit.transpiler.basepasses import BasePass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.exceptions import TranspilerError, CircuitTooWideForTarget
from qiskit.transpiler.instruction_durations import InstructionDurations, InstructionDurationsType
from qiskit.transpiler.passes.synthesis.high_level_synthesis import HLSConfig
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
Expand Down Expand Up @@ -455,7 +455,7 @@ def _check_circuits_coupling_map(circuits, cmap, backend):
# If coupling_map is not None or num_qubits == 1
num_qubits = len(circuit.qubits)
if max_qubits is not None and (num_qubits > max_qubits):
raise TranspilerError(
raise CircuitTooWideForTarget(
f"Number of qubits ({num_qubits}) in {circuit.name} "
f"is greater than maximum ({max_qubits}) in the coupling_map"
)
Expand Down
3 changes: 1 addition & 2 deletions qiskit/pulse/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def __init__(self, index: int):
"""
self._validate_index(index)
self._index = index
self._hash = hash((self.__class__.__name__, self._index))

@property
def index(self) -> Union[int, ParameterExpression]:
Expand Down Expand Up @@ -156,7 +155,7 @@ def __eq__(self, other: "Channel") -> bool:
return type(self) is type(other) and self._index == other._index

def __hash__(self):
return self._hash
return hash((type(self), self._index))


class PulseChannel(Channel, metaclass=ABCMeta):
Expand Down
5 changes: 1 addition & 4 deletions qiskit/pulse/instructions/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(
"""
self._operands = operands
self._name = name
self._hash = None
self._validate()

def _validate(self):
Expand Down Expand Up @@ -301,9 +300,7 @@ def __eq__(self, other: "Instruction") -> bool:
return isinstance(other, type(self)) and self.operands == other.operands

def __hash__(self) -> int:
if self._hash is None:
self._hash = hash((type(self), self.operands, self.name))
return self._hash
return hash((type(self), self.operands, self.name))

def __add__(self, other):
"""Return a new schedule with `other` inserted within `self` at `start_time`.
Expand Down
43 changes: 18 additions & 25 deletions qiskit/pulse/model/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ class Frame(ABC):
The default initial phase for every frame is 0.
"""

def __init__(self, identifier):
"""Create ``Frame``.
Args:
identifier: A unique identifier used to hash the Frame.
"""
self._hash = hash((type(self), identifier))

def __eq__(self, other: "Frame") -> bool:
"""Return True iff self and other are equal, specifically, iff they have the same type and hash.
Args:
other: The frame to compare to this one.
Returns:
True iff equal.
"""
return type(self) is type(other) and self._hash == other._hash

def __hash__(self) -> int:
return self._hash


class GenericFrame(Frame):
"""Pulse module GenericFrame.
Expand All @@ -74,7 +52,6 @@ def __init__(self, name: str):
name: A unique identifier used to identify the frame.
"""
self._name = name
super().__init__(name)

@property
def name(self) -> str:
Expand All @@ -84,6 +61,12 @@ def name(self) -> str:
def __repr__(self) -> str:
return f"GenericFrame({self._name})"

def __eq__(self, other):
return type(self) is type(other) and self._name == other._name

def __hash__(self):
return hash((type(self), self._name))


class QubitFrame(Frame):
"""A frame associated with the driving of a qubit.
Expand All @@ -102,7 +85,6 @@ def __init__(self, index: int):
"""
self._validate_index(index)
self._index = index
super().__init__("QubitFrame" + str(index))

@property
def index(self) -> int:
Expand All @@ -122,6 +104,12 @@ def _validate_index(self, index) -> None:
def __repr__(self) -> str:
return f"QubitFrame({self._index})"

def __eq__(self, other):
return type(self) is type(other) and self._index == other._index

def __hash__(self):
return hash((type(self), self._index))


class MeasurementFrame(Frame):
"""A frame associated with the measurement of a qubit.
Expand All @@ -141,7 +129,6 @@ def __init__(self, index: int):
"""
self._validate_index(index)
self._index = index
super().__init__("MeasurementFrame" + str(index))

@property
def index(self) -> int:
Expand All @@ -160,3 +147,9 @@ def _validate_index(self, index) -> None:

def __repr__(self) -> str:
return f"MeasurementFrame({self._index})"

def __eq__(self, other):
return type(self) is type(other) and self._index == other._index

def __hash__(self):
return hash((type(self), self._index))
3 changes: 1 addition & 2 deletions qiskit/pulse/model/mixed_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(self, pulse_target: PulseTarget, frame: Frame):
"""
self._pulse_target = pulse_target
self._frame = frame
self._hash = hash((self._pulse_target, self._frame, type(self)))

@property
def pulse_target(self) -> PulseTarget:
Expand Down Expand Up @@ -75,4 +74,4 @@ def __eq__(self, other: "MixedFrame") -> bool:
return self._pulse_target == other._pulse_target and self._frame == other._frame

def __hash__(self) -> int:
return self._hash
return hash((self._pulse_target, self._frame, type(self)))
Loading

0 comments on commit a88d66a

Please sign in to comment.