-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_compiler_options.py
More file actions
79 lines (68 loc) · 2.6 KB
/
test_compiler_options.py
File metadata and controls
79 lines (68 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Test submitting compiler options for compilation jobs."""
from typing import Callable, ContextManager
import pytest
from pytket.circuit import Circuit, OpType
import qnexus as qnx
from qnexus.models.references import (
CompilationResultRef,
CompileJobRef,
)
def assert_op_count_in_circuit(
circuit: Circuit, op: OpType, should_be_gt_0: bool
) -> None:
"""Assert that the number of `op` gates in the `circuit` is 0 or >0."""
total_ops = sum([1 for circ_op in circuit.get_commands() if circ_op.op.type == op])
if should_be_gt_0:
assert total_ops > 0, (
f"Expected >0 {op} gates in the circuit, but found {total_ops}."
)
else:
assert total_ops == 0, (
f"Expected 0 {op} gates in the circuit, but found {total_ops}."
)
@pytest.mark.parametrize(
"target_2qb_gate, expect_tk2_gt_0, expect_zzphase_gt_0, expect_zzmax_gt_0",
[
("TK2", True, False, False),
("ZZPhase", False, True, False),
("ZZMax", False, False, True),
],
ids=["TK2", "ZZPhase", "ZZMax"],
)
def test_target_2qb_gate(
create_compile_job_in_project: Callable[..., ContextManager[CompileJobRef]],
test_suite_name: str,
test_case_name: str,
test_qv_circuit: Circuit,
target_2qb_gate: str,
expect_tk2_gt_0: bool,
expect_zzphase_gt_0: bool,
expect_zzmax_gt_0: bool,
) -> None:
"""Test that we can submit compile jobs with different `target_2qb_gate`."""
project_name = f"project for {test_suite_name}"
circuit_name = f"circuit foro {test_case_name}"
compile_job_name = f"compile job for {test_case_name}"
device_name = "H2-Emulator"
config = qnx.QuantinuumConfig(
device_name=device_name,
compiler_options={"target_2qb_gate": target_2qb_gate},
)
with create_compile_job_in_project(
project_name=project_name,
job_name=compile_job_name,
circuit=test_qv_circuit,
circuit_name=circuit_name,
backend_config=config,
skip_intermediate_circuits=True,
) as compile_job_ref:
qnx.jobs.wait_for(compile_job_ref)
compile_result = qnx.jobs.results(compile_job_ref)[0]
assert isinstance(compile_result, CompilationResultRef)
compiled_circuit_ref = compile_result.get_output()
compiled_circuit = compiled_circuit_ref.download_circuit()
assert_op_count_in_circuit(compiled_circuit, OpType.TK2, expect_tk2_gt_0)
assert_op_count_in_circuit(
compiled_circuit, OpType.ZZPhase, expect_zzphase_gt_0
)
assert_op_count_in_circuit(compiled_circuit, OpType.ZZMax, expect_zzmax_gt_0)