Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update black version and fix it to version to 24 #229

Merged
merged 4 commits into from
Feb 22, 2024
Merged
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
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"
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
strategy:
matrix:
include:
- case-name: [email protected].0a1
- case-name: [email protected].0a2
os: ubuntu-latest
qutip-version: '==5.0.0a1'
qutip-version: '==5.0.0a2'
pyqir-version: ''
python-version: '3.10'
- case-name: [email protected]
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:

# For qutip-v5 qutip.control is replaced by qutip-qtrl
- name: Install qutip-qtrl from PyPI
if: ${{ matrix.qutip-version == '@master'}}
if: ${{ matrix.qutip-version == '@master' || startsWith( matrix.qutip-version, '==5') }}
run: |
python -m pip install 'git+https://github.com/qutip/qutip-qtrl.git'

Expand Down
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
2 changes: 1 addition & 1 deletion tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,5 @@ def test_pulse_shape(shape):
coeff, tlist = GateCompiler.generate_pulse_shape(
shape, 1001, maximum=1.0, area=1.0)
assert pytest.approx(coeff[500], 1.e-2) == 1 # max
result = integrate.trapz(coeff, tlist)
result = integrate.trapezoid(coeff, tlist)
assert pytest.approx(result, rel=1.e-2) == 1 # area
Loading