Skip to content

Commit fd97ac7

Browse files
test: add tests for quantum algorithm base class
1 parent 7a749e4 commit fd97ac7

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""Tests for the quantum algorithm base class."""
2+
3+
import pytest
4+
from qualtran.resource_counting import GateCounts
5+
from qualtran.surface_code import AlgorithmSummary, PhysicalCostModel
6+
7+
from quantumthreattracker.algorithms.quantum_algorithm import (
8+
CryptParams,
9+
QuantumAlgorithm,
10+
)
11+
12+
13+
class SampleQuantumAlgorithm(QuantumAlgorithm):
14+
"""Sample instance of the `QuantumAlgorithm` class."""
15+
16+
def get_algorithm_summary(self) -> AlgorithmSummary:
17+
"""Compute logical resource estimates for the circuit.
18+
19+
Returns
20+
-------
21+
AlgorithmSummary
22+
Logical resource estimates.
23+
"""
24+
return AlgorithmSummary(n_algo_qubits=1, n_logical_gates=GateCounts(t=1))
25+
26+
27+
@pytest.fixture()
28+
def default_crypt_params() -> CryptParams:
29+
"""Get a default set of `CryptParams`."""
30+
return CryptParams("RSA", 2048)
31+
32+
33+
@pytest.fixture()
34+
def quantum_algorithm(default_crypt_params: CryptParams) -> QuantumAlgorithm:
35+
"""Get a default `QuantumAlgorithm`."""
36+
return SampleQuantumAlgorithm(crypt_params=default_crypt_params)
37+
38+
39+
def test_setup_crypt_params(quantum_algorithm: QuantumAlgorithm) -> None:
40+
"""Test `_crypt_params` is assigned on `QuantumAlgorithm` initialisation."""
41+
assert quantum_algorithm._crypt_params is not None
42+
43+
44+
def test_algorithm_summary(quantum_algorithm: QuantumAlgorithm) -> None:
45+
"""Test that an algorithm summary is successfully returned."""
46+
assert quantum_algorithm.get_algorithm_summary() is not None
47+
48+
49+
def test_resource_estimation_qualtran(quantum_algorithm: QuantumAlgorithm) -> None:
50+
"""Test that physical resource estimation via Qualtran is successful."""
51+
assert (
52+
quantum_algorithm.estimate_resources_qualtran(
53+
PhysicalCostModel.make_gidney_fowler(data_d=33)
54+
)
55+
is not None
56+
)
57+
58+
59+
def test_resource_estimation_azure(quantum_algorithm: QuantumAlgorithm) -> None:
60+
"""Test that physical resource estimation via Azure is successful."""
61+
assert (
62+
quantum_algorithm.estimate_resources_azure(
63+
{"qubitParams": {"name": "qubit_gate_ns_e3"}}
64+
)
65+
is not None
66+
)
67+
68+
69+
def test_magic_state_factories(quantum_algorithm: QuantumAlgorithm) -> None:
70+
"""Test that at least one T factory is present in the resource estimate."""
71+
estimator_result = quantum_algorithm.estimate_resources_azure(
72+
{"qubitParams": {"name": "qubit_gate_ns_e3"}}
73+
)
74+
assert estimator_result["physicalCounts"]["breakdown"]["numTfactories"] >= 1

0 commit comments

Comments
 (0)