Skip to content

Commit

Permalink
Update black to version 24
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxiLi committed Feb 11, 2024
1 parent 6d2ec92 commit 4ce4465
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ jobs:
- uses: psf/black@stable
with:
options: "--check --diff"
src: "./src"
src: "./src"
version: "~= 24.0"
1 change: 0 additions & 1 deletion src/qutip_qip/algorithms/qft.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This module provides the circuit implementation for Quantum Fourier Transform.
"""


import numpy as np
from ..operations import Gate, snot, cphase, swap, expand_operator
from ..circuit import QubitCircuit
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/circuit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Circuit representation and simulation at the gate level."""

from .circuit import *
from .circuit_latex import *
from .circuitsimulator import *
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/circuit/_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Those decomposition functions should be moved to the
individual gate classes.
"""

import numpy as np
from ..operations import Gate

Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/circuit/circuit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Quantum circuit representation and simulation.
"""

from collections.abc import Iterable
from itertools import product
import inspect
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
For the compatibility between qutip-v5 and v4.
"""

from itertools import chain
from functools import reduce
from packaging.version import parse as parse_version
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/compiler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Compilers for the hardware models in :obj:`device`"""

from .instruction import Instruction
from .scheduler import Scheduler
from .gatecompiler import GateCompiler
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/decompose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Unitary decomposition. (experimental)"""

from .decompose_single_qubit_gate import *
1 change: 1 addition & 0 deletions src/qutip_qip/device/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Simulation of quantum hardware.
"""

from .processor import Processor, Model
from .modelprocessor import ModelProcessor
from .spinchain import (
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/noise.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Noise of quantum hardware."""

import numbers
import warnings
from collections.abc import Iterable
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/operations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Operations on quantum circuits.
"""

from .gates import *
from .gateclass import *
from .measurement import *
1 change: 1 addition & 0 deletions src/qutip_qip/pulse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pulse representation of a quantum circuit."""

from packaging.version import parse as parse_version
import numpy as np
from scipy.interpolate import CubicSpline
Expand Down
7 changes: 4 additions & 3 deletions src/qutip_qip/qasm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Importation and exportation of QASM circuits"""

import re
import os
from itertools import chain
Expand Down Expand Up @@ -505,9 +506,9 @@ def _regs_processor(self, regs, reg_type):
return zip(
*list(
map(
lambda x: x
if isinstance(x, list)
else [x] * expand,
lambda x: (
x if isinstance(x, list) else [x] * expand
),
new_regs,
)
)
Expand Down
18 changes: 9 additions & 9 deletions src/qutip_qip/qir.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,23 @@ def circuit_to_qir(
circuit: QubitCircuit,
format: Union[Literal[QirFormat.BITCODE], Literal["bitcode"]],
module_name: str,
) -> bytes:
...
) -> bytes: ...


@overload
def circuit_to_qir(
circuit: QubitCircuit,
format: Union[Literal[QirFormat.TEXT], Literal["text"]],
module_name: str,
) -> str:
...
) -> str: ...


@overload
def circuit_to_qir(
circuit: QubitCircuit,
format: Union[Literal[QirFormat.MODULE], Literal["module"]],
module_name: str,
) -> pqp.QirModule:
...
) -> pqp.QirModule: ...


def circuit_to_qir(circuit, format, module_name="qutip_circuit"):
Expand Down Expand Up @@ -131,9 +128,12 @@ def append_operation(
if isinstance(
op_with_less_controls.classical_control_value, int
)
else (op_with_less_controls.classical_control_value[1:])
if op_with_less_controls.classical_control_value is not None
else None
else (
(op_with_less_controls.classical_control_value[1:])
if op_with_less_controls.classical_control_value
is not None
else None
)
)
branch_body = {
value: (
Expand Down
40 changes: 25 additions & 15 deletions src/qutip_qip/qiskit/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ def run(self, qiskit_circuit: QuantumCircuit, **run_options) -> Job:
"""
# configure the options
self.set_options(
shots=run_options["shots"]
if "shots" in run_options
else self._default_options().shots,
allow_custom_gate=run_options["allow_custom_gate"]
if "allow_custom_gate" in run_options
else self._default_options().allow_custom_gate,
shots=(
run_options["shots"]
if "shots" in run_options
else self._default_options().shots
),
allow_custom_gate=(
run_options["allow_custom_gate"]
if "allow_custom_gate" in run_options
else self._default_options().allow_custom_gate
),
)
qutip_circ = convert_qiskit_circuit(
qiskit_circuit,
Expand Down Expand Up @@ -212,9 +216,11 @@ def convert_to_hex(count):

header = QobjExperimentHeader.from_dict(
{
"name": qutip_circuit.name
if hasattr(qutip_circuit, "name")
else "",
"name": (
qutip_circuit.name
if hasattr(qutip_circuit, "name")
else ""
),
"n_qubits": qutip_circuit.N,
}
)
Expand Down Expand Up @@ -363,16 +369,20 @@ def _parse_results(

exp_res_data = ExperimentResultData(
counts=counts,
statevector=Statevector(data=final_state.full())
if final_state.type == "ket"
else DensityMatrix(data=final_state.full()),
statevector=(
Statevector(data=final_state.full())
if final_state.type == "ket"
else DensityMatrix(data=final_state.full())
),
)

header = QobjExperimentHeader.from_dict(
{
"name": qutip_circuit.name
if hasattr(qutip_circuit, "name")
else "",
"name": (
qutip_circuit.name
if hasattr(qutip_circuit, "name")
else ""
),
"n_qubits": qutip_circuit.N,
}
)
Expand Down
6 changes: 3 additions & 3 deletions src/qutip_qip/qiskit/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ def convert_qiskit_circuit(
)

unitary = np.array(Operator(qiskit_instruction))
qutip_circuit.user_gates[
qiskit_instruction.name
] = _make_user_gate(unitary, qiskit_instruction)
qutip_circuit.user_gates[qiskit_instruction.name] = (
_make_user_gate(unitary, qiskit_instruction)
)
qutip_circuit.add_gate(
qiskit_instruction.name,
targets=_get_mapped_bits(qiskit_qregs, bit_map=qubit_map),
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/qubits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generating qubit states."""

__all__ = ["qubit_states"]

from qutip import tensor, basis
Expand Down
1 change: 1 addition & 0 deletions src/qutip_qip/vqa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Variational Quantum Algorithms generation and optimization"""

import types
import random
import numpy as np
Expand Down

0 comments on commit 4ce4465

Please sign in to comment.