9
9
import collections
10
10
import operator
11
11
from random import choice
12
+ import logging
13
+
14
+ logger = logging .getLogger (__name__ )
12
15
13
16
import numpy as np
14
- from mitiq import zne , ddd
15
- from mitiq .zne .inference import Factory
16
- from mitiq .zne .scaling import fold_gates_at_random
17
17
import cirq
18
18
19
+ try :
20
+ from mitiq import zne , ddd
21
+ from mitiq .zne .scaling import fold_gates_at_random
22
+
23
+ zne_option = zne
24
+ dd_option = ddd
25
+ except ModuleNotFoundError :
26
+ logger .warning ("mitiq is not installed, please ``pip install mitiq`` first" )
27
+ zne_option = None
28
+ dd_option = None
29
+
19
30
from ... import Circuit
20
31
from ... import backend , gates
21
32
from ...compiler import simple_compiler
22
33
23
34
Gate = gates .Gate
24
35
25
- zne_option = zne
26
-
27
36
28
37
def apply_zne (
29
38
circuit : Any ,
30
39
executor : Callable [[Union [Any , Sequence [Any ]]], Any ],
31
- factory : Optional [Factory ],
32
- scale_noise : Callable [[Any , float ], Any ] = fold_gates_at_random ,
40
+ factory : Optional [Any ],
41
+ scale_noise : Optional [ Callable [[Any , float ], Any ]] = None ,
33
42
num_to_average : int = 1 ,
34
43
** kws : Any ,
35
44
) -> Any :
@@ -50,6 +59,8 @@ def apply_zne(
50
59
:return: Mitigated average value by ZNE.
51
60
:rtype: float
52
61
"""
62
+ if scale_noise is None :
63
+ scale_noise = fold_gates_at_random
53
64
54
65
def executortc (c ): # type: ignore
55
66
c = Circuit .from_qiskit (c , c .num_qubits )
@@ -132,16 +143,11 @@ def add_dd(c: Any, rule: Callable[[int], Any]) -> Any:
132
143
return circuit_dd
133
144
134
145
135
- dd_option = ddd
136
-
137
- # pylint: disable=dangerous-default-value
138
-
139
-
140
146
def apply_dd (
141
147
circuit : Any ,
142
148
executor : Callable [[Any ], Any ],
143
149
rule : Union [Callable [[int ], Any ], List [str ]],
144
- rule_args : Dict [str , Any ] = {} ,
150
+ rule_args : Optional [ Dict [str , Any ]] = None ,
145
151
num_trials : int = 1 ,
146
152
full_output : bool = False ,
147
153
ignore_idle_qubit : bool = True ,
@@ -178,6 +184,8 @@ def apply_dd(
178
184
:return: mitigated expectation value or mitigated expectation value and DD circuit information
179
185
:rtype: Union[float, Tuple[float, Dict[str, Any]]]
180
186
"""
187
+ if rule_args is None :
188
+ rule_args = {}
181
189
182
190
def dd_rule (slack_length : int , spacing : int = - 1 ) -> Any :
183
191
"""
0 commit comments