Skip to content

Commit a21923d

Browse files
authored
Correct default language in docstring for process_circuits(). (#579)
1 parent aba7e77 commit a21923d

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

pytket/extensions/quantinuum/backends/api_wrappers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def get_machine_list(self) -> list[dict[str, Any]]:
525525
self._response_check(res, "get machine list")
526526
jr = res.json()
527527

528-
return cast(list[dict[str, Any]], jr)
528+
return cast("list[dict[str, Any]]", jr)
529529

530530

531531
OFFLINE_MACHINE_LIST = [

pytket/extensions/quantinuum/backends/leakage_gadget.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515

1616

1717
from collections import Counter
18-
from collections.abc import Sequence
19-
from typing import cast
18+
from typing import TYPE_CHECKING, cast
2019

2120
from pytket import Bit, Circuit, OpType, Qubit # type: ignore
2221
from pytket.backends.backendresult import BackendResult
2322
from pytket.utils.outcomearray import OutcomeArray
2423

24+
if TYPE_CHECKING:
25+
from collections.abc import Sequence
26+
2527
LEAKAGE_DETECTION_BIT_NAME_ = "leakage_detection_bit"
2628
LEAKAGE_DETECTION_QUBIT_NAME_ = "leakage_detection_qubit"
2729

@@ -181,5 +183,5 @@ def prune_shots_detected_as_leaky(result: BackendResult) -> BackendResult:
181183
for key, val in discarded_counts.items()
182184
}
183185
),
184-
c_bits=cast(Sequence[Bit], regular_bits),
186+
c_bits=cast("Sequence[Bit]", regular_bits),
185187
)

pytket/extensions/quantinuum/backends/quantinuum.py

+25-23
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ def __init__(
317317

318318
self.api_handler.provider = provider
319319

320-
self._process_circuits_options = cast(dict[str, Any], kwargs.get("options", {}))
320+
self._process_circuits_options = cast(
321+
"dict[str, Any]", kwargs.get("options", {})
322+
)
321323

322324
self._local_emulator_handles: dict[
323325
ResultHandle,
@@ -608,7 +610,7 @@ def _gate_set(self) -> set[OpType]:
608610
return (
609611
_ALL_GATES
610612
if self._MACHINE_DEBUG
611-
else cast(BackendInfo, self.backend_info).gate_set
613+
else cast("BackendInfo", self.backend_info).gate_set
612614
)
613615

614616
@property
@@ -620,7 +622,7 @@ def required_predicates(self) -> list[Predicate]:
620622
if not self._MACHINE_DEBUG:
621623
assert self.backend_info is not None
622624
preds.append(MaxNQubitsPredicate(self.backend_info.n_nodes))
623-
preds.append(MaxNClRegPredicate(cast(int, self.backend_info.n_cl_reg)))
625+
preds.append(MaxNClRegPredicate(cast("int", self.backend_info.n_cl_reg)))
624626
if self.simulator_type == "stabilizer":
625627
preds.append(CliffordCircuitPredicate())
626628

@@ -899,7 +901,7 @@ def get_jobid(handle: ResultHandle) -> str:
899901
:param handle: result handle.
900902
:return: Quantinuum API Job ID string.
901903
"""
902-
return cast(str, handle[0])
904+
return cast("str", handle[0])
903905

904906
@staticmethod
905907
def get_ppcirc_rep(handle: ResultHandle) -> Any:
@@ -909,7 +911,7 @@ def get_ppcirc_rep(handle: ResultHandle) -> Any:
909911
:param handle: result handle
910912
:return: serialized post-processing circuit, if any
911913
"""
912-
return json.loads(cast(str, handle[1]))
914+
return json.loads(cast("str", handle[1]))
913915

914916
@staticmethod
915917
def get_results_width(handle: ResultHandle) -> Optional[int]:
@@ -918,7 +920,7 @@ def get_results_width(handle: ResultHandle) -> Optional[int]:
918920
:param handle: result handle
919921
:return: truncation width of results, if any
920922
"""
921-
n = cast(int, handle[2])
923+
n = cast("int", handle[2])
922924
if n == -1:
923925
return None
924926
else:
@@ -931,7 +933,7 @@ def get_results_selection(handle: ResultHandle) -> Any:
931933
of the expected results in the response. If None, then all results in the
932934
response are used, in lexicographic order.
933935
"""
934-
s = cast(str, handle[3])
936+
s = cast("str", handle[3])
935937
if s == "":
936938
return None
937939
bits = json.loads(s)
@@ -1051,7 +1053,7 @@ def submit_program(
10511053

10521054
# extract job ID from response
10531055
return ResultHandle(
1054-
cast(str, jobdict["job"]),
1056+
cast("str", jobdict["job"]),
10551057
"null",
10561058
-1 if results_selection is None else len(results_selection),
10571059
json.dumps(results_selection),
@@ -1088,7 +1090,7 @@ def process_circuits(
10881090
* `request_options`: extra options to add to the request body as a
10891091
json-style dictionary
10901092
* `language`: languange for submission, of type :py:class:`Language`, default
1091-
QASM.
1093+
QIR.
10921094
* `leakage_detection`: if true, adds additional Qubit and Bit to Circuit
10931095
to detect leakage errors. Run `prune_shots_detected_as_leaky` on returned
10941096
BackendResult to get counts with leakage errors removed.
@@ -1107,7 +1109,7 @@ def process_circuits(
11071109
)
11081110

11091111
if kwargs.get("leakage_detection", False):
1110-
n_device_nodes: int = cast(int, self.backend_info.n_nodes) # type: ignore
1112+
n_device_nodes: int = cast("int", self.backend_info.n_nodes) # type: ignore
11111113
n_leakage_detection_qubits: int = kwargs.get( # type: ignore
11121114
"n_leakage_detection_qubits", n_device_nodes
11131115
)
@@ -1127,17 +1129,17 @@ def process_circuits(
11271129
if valid_check:
11281130
self._check_all_circuits(circuits)
11291131

1130-
postprocess = cast(bool, kwargs.get("postprocess", False))
1132+
postprocess = cast("bool", kwargs.get("postprocess", False))
11311133
simplify_initial = kwargs.get("simplify_initial", False)
1132-
noisy_simulation = cast(bool, kwargs.get("noisy_simulation", True))
1134+
noisy_simulation = cast("bool", kwargs.get("noisy_simulation", True))
11331135

1134-
group = cast(Optional[str], kwargs.get("group", self._group))
1136+
group = cast("Optional[str]", kwargs.get("group", self._group))
11351137

1136-
wasm_fh = cast(Optional[WasmFileHandler], kwargs.get("wasm_file_handler"))
1138+
wasm_fh = cast("Optional[WasmFileHandler]", kwargs.get("wasm_file_handler"))
11371139

1138-
pytket_pass = cast(Optional[BasePass], kwargs.get("pytketpass"))
1140+
pytket_pass = cast("Optional[BasePass]", kwargs.get("pytketpass"))
11391141

1140-
language: Language = cast(Language, kwargs.get("language", Language.QIR))
1142+
language: Language = cast("Language", kwargs.get("language", Language.QIR))
11411143

11421144
handle_list = []
11431145

@@ -1216,7 +1218,7 @@ def process_circuits(
12161218

12171219
quantinuum_circ = b64encode(
12181220
cast(
1219-
bytes,
1221+
"bytes",
12201222
pytket_to_qir(
12211223
c0,
12221224
"circuit generated by pytket-qir",
@@ -1250,9 +1252,9 @@ def process_circuits(
12501252
group=group,
12511253
wasm_file_handler=wasm_fh,
12521254
pytket_pass=pytket_pass,
1253-
options=cast(dict[str, Any], kwargs.get("options", {})),
1255+
options=cast("dict[str, Any]", kwargs.get("options", {})),
12541256
request_options=cast(
1255-
dict[str, Any], kwargs.get("request_options", {})
1257+
"dict[str, Any]", kwargs.get("request_options", {})
12561258
),
12571259
)
12581260

@@ -1298,7 +1300,7 @@ def start_batch(
12981300
# to batch will be recognised as being added to an existing batch
12991301
self.api_handler.retrieve_job_status(
13001302
self.get_jobid(h1),
1301-
use_websocket=cast(bool, kwargs.get("use_websocket", True)),
1303+
use_websocket=cast("bool", kwargs.get("use_websocket", True)),
13021304
)
13031305
return h1
13041306

@@ -1379,7 +1381,7 @@ def circuit_status(
13791381
):
13801382
return CircuitStatus(StatusEnum.COMPLETED)
13811383

1382-
use_websocket = cast(bool, kwargs.get("use_websocket", True))
1384+
use_websocket = cast("bool", kwargs.get("use_websocket", True))
13831385
# TODO check queue position and add to message
13841386
try:
13851387
response = self.api_handler.retrieve_job_status(
@@ -1496,7 +1498,7 @@ def get_result(self, handle: ResultHandle, **kwargs: KwargTypes) -> BackendResul
14961498
wait = kwargs.get("wait")
14971499
if wait is not None:
14981500
wait = int(wait)
1499-
use_websocket = cast(Optional[bool], kwargs.get("use_websocket"))
1501+
use_websocket = cast("Optional[bool]", kwargs.get("use_websocket"))
15001502

15011503
job_retrieve = self._retrieve_job(jobid, timeout, wait, use_websocket)
15021504
circ_status = _parse_status(job_retrieve)
@@ -1692,7 +1694,7 @@ def conv_int(res: str) -> list:
16921694
array_dict[creg] = array_dict[creg][:, :n_bits]
16931695

16941696
stacked_array = cast(
1695-
Sequence[Sequence[int]],
1697+
"Sequence[Sequence[int]]",
16961698
np.hstack([array_dict[name] for name in reversed_creg_names]),
16971699
)
16981700
else:

tests/integration/backend_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def test_postprocess(
497497
c.measure_all()
498498
c = b.get_compiled_circuit(c)
499499
h = b.process_circuit(c, n_shots=10, postprocess=True, language=language)
500-
ppcirc = Circuit.from_dict(json.loads(cast(str, h[1])))
500+
ppcirc = Circuit.from_dict(json.loads(cast("str", h[1])))
501501
ppcmds = ppcirc.get_commands()
502502
assert len(ppcmds) > 0
503503
assert all(ppcmd.op.type == OpType.ClassicalTransform for ppcmd in ppcmds)

tests/unit/leakage_detection_test.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515

1616
from collections import Counter
17-
from collections.abc import Sequence
18-
from typing import cast
17+
from typing import TYPE_CHECKING, cast
1918

2019
import pytest
2120

@@ -30,6 +29,9 @@
3029
)
3130
from pytket.utils.outcomearray import OutcomeArray
3231

32+
if TYPE_CHECKING:
33+
from collections.abc import Sequence
34+
3335

3436
def test_postselection_circuits_1qb_task_gen() -> None:
3537
comparison_circuit: Circuit = Circuit(1, 1)
@@ -193,7 +195,7 @@ def test_postselection_discard_0() -> None:
193195
discard_result = prune_shots_detected_as_leaky(
194196
BackendResult(
195197
counts=counts,
196-
c_bits=cast(Sequence[Bit], [Bit(0), Bit(LEAKAGE_DETECTION_BIT_NAME_, 0)]),
198+
c_bits=cast("Sequence[Bit]", [Bit(0), Bit(LEAKAGE_DETECTION_BIT_NAME_, 0)]),
197199
)
198200
).get_counts()
199201
assert discard_result[(0,)] == 100

0 commit comments

Comments
 (0)