Skip to content

Commit

Permalink
Merge branch 'main' into docs/md_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMacCQ authored Oct 25, 2024
2 parents 65c68b8 + 4af1cbf commit 126392e
Show file tree
Hide file tree
Showing 22 changed files with 373 additions and 300 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ jobs:
- name: Update pip
run: pip install --upgrade pip
- name: Install black and pylint
run: pip install black pylint
run: pip install black pylint ruff
- name: Check files are formatted with black
run: black --check .
run: |
black --check .
- name: Run ruff
run: |
ruff check .
- name: Run pylint
run: pylint */
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enable=
unused-variable,
unused-wildcard-import,
wildcard-import,
wrong-import-order,
wrong-import-position,
yield-outside-function

Expand Down
10 changes: 5 additions & 5 deletions pytket/extensions/qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
"""Module for conversion between IBM Qiskit and tket primitives."""

# _metadata.py is copied to the folder after installation.
from ._metadata import __extension_version__, __extension_name__
from ._metadata import __extension_name__, __extension_version__
from .backends import (
IBMQBackend,
NoIBMQCredentialsError,
AerBackend,
AerDensityMatrixBackend,
AerStateBackend,
AerUnitaryBackend,
AerDensityMatrixBackend,
IBMQBackend,
IBMQEmulatorBackend,
NoIBMQCredentialsError,
)
from .backends.config import set_ibmq_config
from .qiskit_convert import qiskit_to_tk, tk_to_qiskit, process_characterisation
from .qiskit_convert import process_characterisation, qiskit_to_tk, tk_to_qiskit

# from .tket_pass import TketPass
4 changes: 2 additions & 2 deletions pytket/extensions/qiskit/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# limitations under the License.
"""Backends for connecting to IBM devices and simulators directly from pytket"""

from .ibm import IBMQBackend, NoIBMQCredentialsError
from .aer import (
AerBackend,
AerDensityMatrixBackend,
AerStateBackend,
AerUnitaryBackend,
AerDensityMatrixBackend,
qiskit_aer_backend,
)
from .ibm import IBMQBackend, NoIBMQCredentialsError
from .ibmq_emulator import IBMQEmulatorBackend
65 changes: 32 additions & 33 deletions pytket/extensions/qiskit/backends/aer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,73 @@
# limitations under the License.

import itertools
import json
import warnings
from collections import defaultdict
from collections.abc import Sequence
from dataclasses import dataclass
import json
from logging import warning
from typing import Optional, Sequence, Any, cast, TYPE_CHECKING
import warnings
from typing import TYPE_CHECKING, Any, Optional, cast

import numpy as np
from qiskit import transpile # type: ignore
from qiskit_aer.noise import NoiseModel # type: ignore
from qiskit.quantum_info.operators import Pauli as qk_Pauli # type: ignore
from qiskit.quantum_info.operators.symplectic.sparse_pauli_op import SparsePauliOp # type: ignore
from qiskit_aer import Aer # type: ignore
from qiskit_aer.library import save_expectation_value # type: ignore # pylint: disable=unused-import
from qiskit_aer.noise import NoiseModel # type: ignore

from pytket.architecture import Architecture, FullyConnected
from pytket.backends import Backend, CircuitNotRunError, CircuitStatus, ResultHandle
from pytket.backends.backendinfo import BackendInfo
from pytket.backends.backendresult import BackendResult
from pytket.backends.resulthandle import _ResultIdTuple
from pytket.circuit import Circuit, Node, OpType, Qubit
from pytket.passes import (
AutoRebase,
BasePass,
CliffordSimp,
CXMappingPass,
DecomposeBoxes,
FullPeepholeOptimise,
NaivePlacementPass,
SequencePass,
SynthesiseTket,
AutoRebase,
NaivePlacementPass,
)
from pytket.pauli import Pauli, QubitPauliString
from pytket.placement import NoiseAwarePlacement
from pytket.predicates import (
ConnectivityPredicate,
DefaultRegisterPredicate,
GateSetPredicate,
NoClassicalControlPredicate,
NoBarriersPredicate,
NoClassicalControlPredicate,
NoFastFeedforwardPredicate,
NoSymbolsPredicate,
DefaultRegisterPredicate,
Predicate,
)
from pytket.utils import prepare_circuit
from pytket.utils.operators import QubitPauliOperator
from pytket.utils.results import KwargTypes
from pytket.utils import prepare_circuit
from qiskit import transpile # type: ignore
from qiskit.quantum_info.operators import Pauli as qk_Pauli # type: ignore
from qiskit.quantum_info.operators.symplectic.sparse_pauli_op import ( # type: ignore
SparsePauliOp,
)

from .ibm_utils import _STATUS_MAP, _batch_circuits
from .._metadata import __extension_version__
from ..qiskit_convert import (
tk_to_qiskit,
_gate_str_2_optype,
tk_to_qiskit,
)
from ..result_convert import qiskit_result_to_backendresult
from .crosstalk_model import (
NoisyCircuitBuilder,
CrosstalkParams,
NoisyCircuitBuilder,
)
from .ibm_utils import _STATUS_MAP, _batch_circuits

if TYPE_CHECKING:
from qiskit_aer import AerJob
from qiskit_aer.backends.aerbackend import AerBackend as QiskitAerBackend # type: ignore
from qiskit_aer.backends.aerbackend import ( # type: ignore
AerBackend as QiskitAerBackend,
)


def _default_q_index(q: Qubit) -> int:
Expand Down Expand Up @@ -326,14 +331,14 @@ def process_circuits(
return cast(list[ResultHandle], handle_list)

def cancel(self, handle: ResultHandle) -> None:
job: "AerJob" = self._cache[handle]["job"]
job: AerJob = self._cache[handle]["job"]
cancelled = job.cancel()
if not cancelled:
warning(f"Unable to cancel job {cast(str, handle[0])}")

def circuit_status(self, handle: ResultHandle) -> CircuitStatus:
self._check_handle_type(handle)
job: "AerJob" = self._cache[handle]["job"]
job: AerJob = self._cache[handle]["job"]
ibmstatus = job.status()
return CircuitStatus(_STATUS_MAP[ibmstatus], ibmstatus.value)

Expand All @@ -343,7 +348,7 @@ def get_result(self, handle: ResultHandle, **kwargs: KwargTypes) -> BackendResul
except CircuitNotRunError:
jobid, _, qubit_n, ppc = handle
try:
job: "AerJob" = self._cache[handle]["job"]
job: AerJob = self._cache[handle]["job"]
except KeyError:
raise CircuitNotRunError(handle)

Expand Down Expand Up @@ -406,10 +411,8 @@ def get_pauli_expectation_value(
"""
if self._noise_model:
raise RuntimeError(
(
"Snapshot based expectation value not supported with noise model. "
"Use shots."
)
"Snapshot based expectation value not supported with noise model. "
"Use shots."
)
if not self._supports_expectation:
raise NotImplementedError("Cannot get expectation value from this backend")
Expand All @@ -436,10 +439,8 @@ def get_operator_expectation_value(
"""
if self._noise_model:
raise RuntimeError(
(
"Snapshot based expectation value not supported with noise model. "
"Use shots."
)
"Snapshot based expectation value not supported with noise model. "
"Use shots."
)
if not self._supports_expectation:
raise NotImplementedError("Cannot get expectation value from this backend")
Expand Down Expand Up @@ -754,11 +755,9 @@ def _process_noise_model(
raise RuntimeWarning("Error applies to multiple gates.")
if "gate_qubits" not in error:
raise RuntimeWarning(
(
"Please define NoiseModel without using the"
" add_all_qubit_quantum_error()"
" or add_all_qubit_readout_error() method."
)
"Please define NoiseModel without using the"
" add_all_qubit_quantum_error()"
" or add_all_qubit_readout_error() method."
)
name = name[0]

Expand Down
9 changes: 5 additions & 4 deletions pytket/extensions/qiskit/backends/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, ClassVar, Optional, Type
from dataclasses import dataclass
from typing import Any, ClassVar, Optional

from pytket.config import PytketExtConfig


Expand All @@ -28,11 +29,11 @@ class QiskitConfig(PytketExtConfig):

@classmethod
def from_extension_dict(
cls: Type["QiskitConfig"], ext_dict: dict[str, Any]
cls: type["QiskitConfig"], ext_dict: dict[str, Any]
) -> "QiskitConfig":
return cls(
ext_dict.get("instance", None),
ext_dict.get("ibmq_api_token", None),
ext_dict.get("instance"),
ext_dict.get("ibmq_api_token"),
)


Expand Down
18 changes: 10 additions & 8 deletions pytket/extensions/qiskit/backends/crosstalk_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,29 @@
# limitations under the License.


from typing import Optional
from dataclasses import dataclass

from qiskit_aer.noise import NoiseModel # type: ignore
from qiskit_aer.noise.errors.standard_errors import amplitude_damping_error, phase_damping_error # type: ignore
from typing import Optional

import numpy as np
from qiskit_aer.noise import NoiseModel # type: ignore
from qiskit_aer.noise.errors.standard_errors import ( # type: ignore
amplitude_damping_error,
phase_damping_error,
)
from scipy.linalg import fractional_matrix_power # type: ignore

from pytket.backends.backendinfo import BackendInfo
from pytket.circuit import (
Circuit,
Qubit,
Node,
Command,
OpType,
Node,
Op,
OpType,
Qubit,
Unitary1qBox,
Unitary2qBox,
Unitary3qBox,
)
from pytket.backends.backendinfo import BackendInfo
from pytket.extensions.qiskit.qiskit_convert import _gate_str_2_optype


Expand Down
Loading

0 comments on commit 126392e

Please sign in to comment.