Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from pathlib import Path
from typing import Callable, ContextManager, Generator, Literal, Union, cast

import numpy as np
import pandas as pd
import pytest
from hugr.package import Package
from pytket.circuit import Circuit
from pytket.circuit import CircBox, Circuit, Unitary2qBox
from pytket.qir import pytket_to_qir # type: ignore[attr-defined]
from pytket.wasm.wasm import WasmFileHandler, WasmModuleHandler
from quantinuum_schemas.models.backend_config import (
Expand All @@ -24,6 +25,7 @@
SeleneConfig,
SelenePlusConfig,
)
from scipy.stats import unitary_group

import qnexus as qnx
from qnexus.client.auth import login_no_interaction
Expand Down Expand Up @@ -547,6 +549,35 @@ def test_circuit() -> Circuit:
return circuit


@pytest.fixture()
def test_qv_circuit() -> Circuit:
"""A Quantum Volume pytket circuit.

Note: see https://docs.quantinuum.com/systems/trainings/h2/getting_started/parameterized_angle_2_qubit_gates.html#quantum-volume-test
"""

def haar_random_su4_box() -> CircBox:
"""Returns a CircBox that decomposes a random general SU(4) unitary
into a circuit of 2 qubits distributed with the Haar Measure."""
r = unitary_group.rvs(dim=4)
r[0, :] /= np.linalg.det(r)
circuit = Circuit(2)
box = Unitary2qBox(r)
circuit.add_unitary2qbox(box, 0, 1)
return CircBox(circuit)

qv_circuit_size = 6
qv_circuit = Circuit(qv_circuit_size)
for _ in range(qv_circuit_size):
permutation = np.random.permutation(len(qv_circuit.qubits))
for i in range(0, qv_circuit_size, 2):
box = haar_random_su4_box()
qv_circuit.add_circbox(box, [permutation[i], permutation[i + 1]])
qv_circuit.measure_all()

return qv_circuit


def _get_or_create_circuit(
circuit: Circuit,
project_name: str,
Expand Down
79 changes: 79 additions & 0 deletions integration/test_compiler_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dev = [
"pytest-xdist>=3.6.1",
"guppylang >=0.21.0, <1.0.0",
"pytket-qir>=0.22.0",
"scipy-stubs>=1.15.3.0",
]


Expand Down
Loading
Loading