Skip to content

Commit e7e8ecc

Browse files
further fix rtd issue
1 parent afc36a1 commit e7e8ecc

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

.readthedocs.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
formats:
9+
- pdf
10+
11+
# Set the version of Python and other tools you might need
12+
build:
13+
os: ubuntu-20.04
14+
tools:
15+
python: "3.8"
16+
17+
# Build documentation in the docs/ directory with Sphinx
18+
sphinx:
19+
configuration: docs/conf.py
20+
# We recommend specifying your dependencies to enable reproducible builds:
21+
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
22+
python:
23+
install:
24+
- requirements: requirements/requirements-rtd.txt

requirements/requirements-rtd.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ scipy
33
cirq
44
tensorflow
55
tensornetwork
6-
mitiq
76
graphviz
87
networkx
98
jax

tensorcircuit/results/qem/qem_methods.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,36 @@
99
import collections
1010
import operator
1111
from random import choice
12+
import logging
13+
14+
logger = logging.getLogger(__name__)
1215

1316
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
1717
import cirq
1818

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+
1930
from ... import Circuit
2031
from ... import backend, gates
2132
from ...compiler import simple_compiler
2233

2334
Gate = gates.Gate
2435

25-
zne_option = zne
26-
2736

2837
def apply_zne(
2938
circuit: Any,
3039
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,
3342
num_to_average: int = 1,
3443
**kws: Any,
3544
) -> Any:
@@ -50,6 +59,8 @@ def apply_zne(
5059
:return: Mitigated average value by ZNE.
5160
:rtype: float
5261
"""
62+
if scale_noise is None:
63+
scale_noise = fold_gates_at_random
5364

5465
def executortc(c): # type: ignore
5566
c = Circuit.from_qiskit(c, c.num_qubits)
@@ -132,16 +143,11 @@ def add_dd(c: Any, rule: Callable[[int], Any]) -> Any:
132143
return circuit_dd
133144

134145

135-
dd_option = ddd
136-
137-
# pylint: disable=dangerous-default-value
138-
139-
140146
def apply_dd(
141147
circuit: Any,
142148
executor: Callable[[Any], Any],
143149
rule: Union[Callable[[int], Any], List[str]],
144-
rule_args: Dict[str, Any] = {},
150+
rule_args: Optional[Dict[str, Any]] = None,
145151
num_trials: int = 1,
146152
full_output: bool = False,
147153
ignore_idle_qubit: bool = True,
@@ -178,6 +184,8 @@ def apply_dd(
178184
:return: mitigated expectation value or mitigated expectation value and DD circuit information
179185
:rtype: Union[float, Tuple[float, Dict[str, Any]]]
180186
"""
187+
if rule_args is None:
188+
rule_args = {}
181189

182190
def dd_rule(slack_length: int, spacing: int = -1) -> Any:
183191
"""

0 commit comments

Comments
 (0)