Skip to content

Commit

Permalink
Merge pull request #102 from BQSKit/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
edyounis authored Jan 19, 2023
2 parents 682c332 + e3ceab1 commit cfc44ec
Show file tree
Hide file tree
Showing 39 changed files with 40 additions and 108 deletions.
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
skip: [mypy]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -24,7 +24,7 @@ repos:
- id: no-commit-to-branch
args: [--branch, master]
- repo: https://github.com/PyCQA/docformatter
rev: v1.5.0
rev: v1.5.1
hooks:
- id: docformatter
args:
Expand All @@ -33,15 +33,15 @@ repos:
- --wrap-summaries=80
- --wrap-descriptions=80
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.7.0
rev: v2.0.1
hooks:
- id: autopep8
args:
- --in-place
- --max-line-length=80
- --ignore=E731
- repo: https://github.com/asottile/pyupgrade
rev: v3.1.0
rev: v3.3.1
hooks:
- id: pyupgrade
args:
Expand All @@ -55,7 +55,7 @@ repos:
- from __future__ import annotations
- --py37-plus
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.3.0
rev: v2.4.0
hooks:
- id: add-trailing-comma
args:
Expand All @@ -65,19 +65,19 @@ repos:
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/PyCQA/autoflake
rev: v1.7.7
rev: v2.0.0
hooks:
- id: autoflake
args:
- --in-place
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v0.991
hooks:
- id: mypy
exclude: tests/qis/test_pauli.py
additional_dependencies: ["numpy>=1.21"]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
args:
Expand Down
2 changes: 1 addition & 1 deletion bqskit/exec/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def get_counts(self, shots: int) -> npt.NDArray[np.int64]:
return np.asarray(np.multiply(shots, self.probs), np.int64)

def __str__(self) -> str:
pass
return str(self.probs)
4 changes: 2 additions & 2 deletions bqskit/ext/rigetti.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# Ring 4-5
(25, 38), (26, 37),
])
"""Retrieved August 31, 2022: https://qcs.rigetti.com/qpus"""
"""Retrieved August 31, 2022: https://qcs.rigetti.com/qpus."""

_octo_rings = [
[
Expand Down Expand Up @@ -77,7 +77,7 @@
_links.extend(l)

_aspen_m2_coupling_graph = CouplingGraph(_links)
"""Retrieved August 31, 2022: https://qcs.rigetti.com/qpus"""
"""Retrieved August 31, 2022: https://qcs.rigetti.com/qpus."""

Aspen11Model = MachineModel(40, _aspen_11_coupling_graph, rigetti_gate_set)
"""A BQSKit MachineModel for Rigetti's Aspen-11 quantum processor."""
Expand Down
20 changes: 10 additions & 10 deletions bqskit/ir/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2090,8 +2090,9 @@ def surround(

HalfWire = Tuple[CircuitPoint, str]
"""
A HalfWire is a point in the circuit and a direction. This
represents a point to start exploring from and a direction to
A HalfWire is a point in the circuit and a direction.
This represents a point to start exploring from and a direction to
explore in.
"""

Expand All @@ -2104,14 +2105,13 @@ def surround(
"""
A Node in the search tree.
Each node represents a region that may grow further.
The data structure tracks all HalfWires in the region and
the set of operations inside the region. During node exploration
each HalfWire is walked until we find a multi-qudit gate. Multi-
qudit gates form branches in the tree on whether on the gate
should be included. The node structure additionally stores the
set of qudit indices involved in the region currently. Also, we
track points that have already been explored to reduce repetition.
Each node represents a region that may grow further. The data structure
tracks all HalfWires in the region and the set of operations inside the
region. During node exploration each HalfWire is walked until we find a
multi-qudit gate. Multi- qudit gates form branches in the tree on
whether on the gate should be included. The node structure additionally
stores the set of qudit indices involved in the region currently. Also,
we track points that have already been explored to reduce repetition.
"""

# Initialize the frontier
Expand Down
12 changes: 6 additions & 6 deletions bqskit/ir/gates/composedgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class ComposedGate(Gate):
def is_differentiable(self) -> bool:
"""Check if all sub gates are differentiable."""
if hasattr(self, 'gate'):
return isinstance(self.gate, DifferentiableUnitary) # type: ignore
return isinstance(self.gate, DifferentiableUnitary)
if hasattr(self, 'gates'):
return all(
isinstance(gate, DifferentiableUnitary)
for gate in self.gates # type: ignore
for gate in self.gates
)

raise AttributeError(
Expand All @@ -40,12 +40,12 @@ def is_locally_optimizable(self) -> bool:
"""Check if all sub gates are locally optimizable."""
if hasattr(self, 'gate'):
return isinstance(
self.gate, LocallyOptimizableUnitary, # type: ignore
self.gate, LocallyOptimizableUnitary,
)
if hasattr(self, 'gates'):
return all(
isinstance(gate, LocallyOptimizableUnitary)
for gate in self.gates # type: ignore
for gate in self.gates
)

raise AttributeError(
Expand All @@ -55,9 +55,9 @@ def is_locally_optimizable(self) -> bool:

def __hash__(self) -> int:
if hasattr(self, 'gate'):
return hash((self.name, self.gate)) # type: ignore
return hash((self.name, self.gate))
if hasattr(self, 'gates'):
return hash((self.name, tuple(self.gates))) # type: ignore
return hash((self.name, tuple(self.gates)))
raise RuntimeError(
f"Composed gate '{self.name}' has no attribute 'gate' or 'gates'.",
)
Expand Down
2 changes: 1 addition & 1 deletion bqskit/ir/opt/instantiaters/qfactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def instantiate(
x0: npt.NDArray[np.float64],
) -> npt.NDArray[np.float64]:
"""Instantiate `circuit`, see Instantiater for more info."""
return super().instantiate(circuit, target, x0)
return QFactorInstantiatorNative.instantiate(self, circuit, target, x0)

@staticmethod
def is_capable(circuit: Circuit) -> bool:
Expand Down
1 change: 0 additions & 1 deletion bqskit/ir/opt/multistartgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class MultiStartGenerator(abc.ABC):

@abc.abstractmethod
def gen_starting_points(
self,
Expand Down
1 change: 0 additions & 1 deletion tests/ext/test_cirq.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class TestTranslate:

@pytest.fixture
def bqskit_circuit(self) -> Circuit:
circuit = Circuit(3)
Expand Down
1 change: 0 additions & 1 deletion tests/ext/test_pytket.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class TestTranslate:

@pytest.fixture
def bqskit_circuit(self) -> Circuit:
circuit = Circuit(3)
Expand Down
1 change: 0 additions & 1 deletion tests/ext/test_qiskit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class TestTranslate:

@pytest.fixture
def bqskit_circuit(self) -> Circuit:
circuit = Circuit(3)
Expand Down
1 change: 0 additions & 1 deletion tests/ext/test_qutip.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class TestTranslate:

@pytest.fixture
def bqskit_circuit(self) -> Circuit:
circuit = Circuit(3)
Expand Down
3 changes: 0 additions & 3 deletions tests/ir/circuit/test_point_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class TestIsPointInRange:

@valid_type_test(Circuit(1).is_point_in_range)
def test_valid_type(self) -> None:
pass
Expand Down Expand Up @@ -111,7 +110,6 @@ def test_false_pos(self, point: CircuitPointLike) -> None:


class TestIsPointIdle:

@valid_type_test(Circuit(1).is_point_idle)
def test_valid_type(self) -> None:
pass
Expand Down Expand Up @@ -141,7 +139,6 @@ def test_not_idle(self, circuit: Circuit) -> None:


class TestNormalizePoint:

@valid_type_test(Circuit(1).normalize_point)
def test_valid_type(self) -> None:
pass
Expand Down
2 changes: 0 additions & 2 deletions tests/ir/gates/parameterized/test_unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class TestInit:

@given(num_qudits_and_radixes(3, (2, 3)))
def test_valid(self, pair: tuple[int, tuple[int, ...]]) -> None:
num_qudits, radixes = pair
Expand All @@ -29,7 +28,6 @@ def test_invalid(self, num_qudits: int) -> None:


class TestGetUnitary:

@given(unitaries())
def test_exact(self, utry: UnitaryMatrix) -> None:
params = list(np.reshape(np.real(utry.numpy), (-1,))) + \
Expand Down
1 change: 0 additions & 1 deletion tests/ir/gates/test_circuitgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class TestPickle:

@given(circuits([2, 2], max_gates=3), circuits([2, 2], max_gates=3))
def test_pickle_individual(self, c1: Circuit, c2: Circuit) -> None:
gate1 = CircuitGate(c1)
Expand Down
1 change: 0 additions & 1 deletion tests/ir/lang/test_qasm_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ def test_nested_gate_decl(self) -> None:


class TestIncludeStatements:

def test_include_no_exists(self) -> None:
input = """
OPENQASM 2.0;
Expand Down
1 change: 0 additions & 1 deletion tests/ir/opt/instantiaters/test_qfactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class TestQFactorEndToEnd:

def test_no_change(self) -> None:
u1 = unitary_group.rvs(8)
g1 = VariableUnitaryGate(3)
Expand Down
1 change: 0 additions & 1 deletion tests/ir/test_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class TestBasicGate:

def test_get_name(self, gate: Gate) -> None:
assert isinstance(gate.name, str)

Expand Down
6 changes: 0 additions & 6 deletions tests/ir/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def test_strategy(interval: CycleInterval) -> None:


class TestCycleIntervalNew:

@valid_type_test(CycleInterval)
def test_valid_type(self) -> None:
pass
Expand Down Expand Up @@ -100,7 +99,6 @@ def test_indices(interval: CycleInterval) -> None:


class TestCycleIntervalOverlaps:

@valid_type_test(CycleInterval(0, 0).overlaps)
def test_valid_type(self) -> None:
pass
Expand All @@ -122,7 +120,6 @@ def test_overlaps(


class TestCycleIntervalIntersection:

@valid_type_test(CycleInterval(0, 0).intersection)
def test_valid_type(self) -> None:
pass
Expand Down Expand Up @@ -159,7 +156,6 @@ def test_valid(


class TestCycleIntervalUnion:

@valid_type_test(CycleInterval(0, 0).union)
def test_valid_type(self) -> None:
pass
Expand Down Expand Up @@ -196,7 +192,6 @@ def test_valid(


class TestCycleIntervalLt:

@given(cycle_intervals(), everything_except(tuple))
# @example(CycleInterval(0, 0), tuple())
def test_invalid(self, interval: CycleInterval, other: Any) -> None:
Expand All @@ -222,7 +217,6 @@ def test_valid(


class TestCycleIntervalIsBounds:

@given(cycle_intervals())
def test_true_1(self, interval: CycleInterval) -> None:
assert CycleInterval.is_interval(interval)
Expand Down
1 change: 0 additions & 1 deletion tests/ir/test_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


class TestCircuitIterator:

def test_empty(self) -> None:
circuit = Circuit(1)
ops = [cast(Operation, op) for op in CircuitIterator(circuit)]
Expand Down
3 changes: 0 additions & 3 deletions tests/ir/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


class TestInit:

@invalid_type_test(CircuitLocation)
def test_invalid_type(self) -> None:
pass
Expand All @@ -31,7 +30,6 @@ def test_from_list(self, loc: list[int]) -> None:


class TestUnion:

@given(circuit_locations())
def test_self(self, loc: CircuitLocation) -> None:
assert set(loc.union(loc)) == set(loc)
Expand All @@ -46,7 +44,6 @@ def test_other(self, l1: CircuitLocation, l2: CircuitLocationLike) -> None:


class TestIntersection:

@given(circuit_locations())
def test_self(self, loc: CircuitLocation) -> None:
assert loc.intersection(loc) == loc
Expand Down
1 change: 0 additions & 1 deletion tests/ir/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def test_init(op: Operation) -> None:


class TestGetQasm:

def test_cx(self) -> None:
op = Operation(CXGate(), (0, 1))
assert op.get_qasm() == 'cx q[0], q[1];\n'
Expand Down
3 changes: 0 additions & 3 deletions tests/ir/test_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


class TestNew:

@invalid_type_test(CircuitPoint)
def test_invalid_type(self) -> None:
pass
Expand Down Expand Up @@ -56,7 +55,6 @@ def test_invalid(self, cycle: int) -> None:


class TestIsPoint:

@given(circuit_points())
def test_from_point(self, point: CircuitPoint) -> None:
assert CircuitPoint.is_point(point)
Expand All @@ -71,7 +69,6 @@ def test_false(self, not_a_point: Any) -> None:


class TestConversionToTuple:

@given(circuit_points())
def test_from_point(self, point: CircuitPoint) -> None:
assert isinstance(point, tuple)
Expand Down
Loading

0 comments on commit cfc44ec

Please sign in to comment.