2
2
3
3
from copy import deepcopy
4
4
from numbers import Complex
5
- from typing import Iterable , Optional , Sequence , Type , Union
5
+ from typing import TYPE_CHECKING , Iterable , Optional , Sequence , Type , Union
6
+
7
+ if TYPE_CHECKING :
8
+ from qat .core .wrappers .circuit import Circuit as myQLM_Circuit
9
+ from cirq .circuits .circuit import Circuit as cirq_Circuit
10
+ from braket .circuits import Circuit as braket_Circuit
11
+ from qiskit .circuit import QuantumCircuit
6
12
7
13
import numpy as np
8
14
import numpy .typing as npt
9
- from braket .circuits import Circuit as braket_Circuit
10
- from cirq .circuits .circuit import Circuit as cirq_Circuit
11
15
from matplotlib .figure import Figure
12
- from qat .core .wrappers .circuit import Circuit as myQLM_Circuit
13
- from qiskit .circuit import Operation , QuantumCircuit
14
- from qiskit .circuit .quantumcircuit import CircuitInstruction
15
- from qiskit .quantum_info import Operator
16
16
from sympy import Basic , Expr
17
17
from typeguard import TypeCheckError , typechecked
18
18
@@ -626,6 +626,10 @@ def to_other_language(self, language: Language = Language.QISKIT) -> Union[
626
626
"""
627
627
628
628
if language == Language .QISKIT :
629
+ from qiskit .circuit import Operation , QuantumCircuit
630
+ from qiskit .circuit .quantumcircuit import CircuitInstruction
631
+ from qiskit .quantum_info import Operator
632
+
629
633
# to avoid defining twice the same parameter, we keep trace of the
630
634
# added parameters, and we use those instead of new ones when they
631
635
# are used more than once
@@ -642,15 +646,16 @@ def to_other_language(self, language: Language = Language.QISKIT) -> Union[
642
646
qiskit_inst = instruction .to_other_language (
643
647
Language .QISKIT , qiskit_parameters
644
648
)
645
- assert (
646
- isinstance (qiskit_inst , CircuitInstruction )
647
- or isinstance (qiskit_inst , Operation )
648
- or isinstance (qiskit_inst , Operator )
649
- )
649
+ if TYPE_CHECKING :
650
+ assert (
651
+ isinstance (qiskit_inst , CircuitInstruction )
652
+ or isinstance (qiskit_inst , Operation )
653
+ or isinstance (qiskit_inst , Operator )
654
+ )
650
655
cargs = []
651
656
652
657
if isinstance (instruction , CustomGate ):
653
- new_circ .unitary (
658
+ new_circ .unitary ( # pyright: ignore[reportAttributeAccessIssue]
654
659
instruction .to_other_language (),
655
660
instruction .targets ,
656
661
instruction .label ,
@@ -674,8 +679,9 @@ def to_other_language(self, language: Language = Language.QISKIT) -> Union[
674
679
qargs = range (instruction .size )
675
680
else :
676
681
raise ValueError (f"Instruction not handled: { instruction } " )
677
- assert not isinstance (qiskit_inst , Operator )
678
682
683
+ if TYPE_CHECKING :
684
+ assert not isinstance (qiskit_inst , Operator )
679
685
new_circ .append (
680
686
qiskit_inst ,
681
687
qargs ,
@@ -734,7 +740,8 @@ def to_qasm2(self) -> str:
734
740
qiskit_circ = self .subs ({}, remove_symbolic = True ).to_other_language (
735
741
Language .QISKIT
736
742
)
737
- assert isinstance (qiskit_circ , QuantumCircuit )
743
+ if TYPE_CHECKING :
744
+ assert isinstance (qiskit_circ , QuantumCircuit )
738
745
qasm = qiskit_circ .qasm ()
739
746
assert qasm is not None
740
747
return qasm
0 commit comments