Skip to content

Commit

Permalink
check if default two qubit gate is supported by the device (#472)
Browse files Browse the repository at this point in the history
* add check for 2 qubit gate

* move check to constructor of backend

* update secrets in cal workflow

* add assert for mypy

* clean up

* update default register size to 64

* oRevert "update default register size to 64"

This reverts commit e89a991.
  • Loading branch information
cqc-melf authored Jul 16, 2024
1 parent 597eebc commit e27e08b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ jobs:
- name: Run tests with mpl test
env:
PYTKET_RUN_MPL_TESTS: 1
PYTKET_REMOTE_QUANTINUUM_USERNAME_QA: ${{ secrets.PYTKET_REMOTE_QUANTINUUM_USERNAME }}
PYTKET_REMOTE_QUANTINUUM_PASSWORD_QA: ${{ secrets.PYTKET_REMOTE_QUANTINUUM_USERNAME }}
PYTKET_REMOTE_QUANTINUUM_USERNAME_QA: ${{ secrets.PYTKET_REMOTE_QUANTINUUM_USERNAME_QA }}
PYTKET_REMOTE_QUANTINUUM_PASSWORD_QA: ${{ secrets.PYTKET_REMOTE_QUANTINUUM_PASSWORD_QA }}
working-directory: ./tests
run: |
pytest --mpl-generate-path=integration/baseline
Expand Down
8 changes: 8 additions & 0 deletions pytket/extensions/quantinuum/backends/quantinuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ def __init__(
] = dict()

self._default_2q_gate = _default_2q_gate(device_name)

if self._default_2q_gate in self.two_qubit_gate_set:
pass
elif len(self.two_qubit_gate_set) > 0:
self._default_2q_gate = list(self.two_qubit_gate_set)[0]
else:
raise ValueError("The device is not supporting any two qubit gates")

if compilation_config is None:
self.compilation_config = QuantinuumBackendCompilationConfig(
allow_implicit_swaps=True, target_2qb_gate=self._default_2q_gate
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/api1_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,13 @@ def test_custom_login_flow(
),
)

qcc = QuantinuumConfigCredentialStorage()
qcc.save_user_name("user3")
qcc.save_refresh_token("token")

backend_3 = QuantinuumBackend(
device_name=fake_device,
api_handler=QuantinuumAPI(QuantinuumConfigCredentialStorage()),
api_handler=QuantinuumAPI(qcc),
)

circ = Circuit(2, name="default_login_flow_test").H(0).CX(0, 1).measure_all()
Expand Down Expand Up @@ -391,9 +395,8 @@ def test_device_family(
)

backend = QuantinuumBackend(
device_name=chosen_device,
device_name=chosen_device, api_handler=mock_quum_api_handler
)
backend.api_handler = mock_quum_api_handler

circ = Circuit(2, name="batching_test").H(0).CX(0, 1).measure_all()
circ = backend.get_compiled_circuit(circ)
Expand Down Expand Up @@ -443,8 +446,8 @@ def test_resumed_batching(

backend = QuantinuumBackend(
device_name="H1-1E",
api_handler=mock_quum_api_handler,
)
backend.api_handler = mock_quum_api_handler

circ = Circuit(2, name="batching_test").H(0).CX(0, 1).measure_all()
circ = backend.get_compiled_circuit(circ)
Expand Down Expand Up @@ -553,8 +556,8 @@ def test_submit_qasm_api(

backend = QuantinuumBackend(
device_name="H1-1SC",
api_handler=mock_quum_api_handler,
)
backend.api_handler = mock_quum_api_handler

qasm = """
OPENQASM 2.0;
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/offline_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def test_shots_bits_edgecases(n_shots, n_bits, language: Language) -> None:
@pytest.mark.parametrize("device_name", pytest.ALL_DEVICE_NAMES) # type: ignore
def test_defaultapi_handler(device_name: str) -> None:
"""Test that the default API handler is used on backend construction."""
backend_1 = QuantinuumBackend(device_name)
backend_2 = QuantinuumBackend(device_name)
backend_1 = QuantinuumBackend(device_name, machine_debug=True)
backend_2 = QuantinuumBackend(device_name, machine_debug=True)

assert backend_1.api_handler is backend_2.api_handler

Expand All @@ -163,8 +163,12 @@ def test_custom_api_handler(device_name: str) -> None:
handler_1 = QuantinuumAPI()
handler_2 = QuantinuumAPI()

backend_1 = QuantinuumBackend(device_name, api_handler=handler_1)
backend_2 = QuantinuumBackend(device_name, api_handler=handler_2)
backend_1 = QuantinuumBackend(
device_name, api_handler=handler_1, machine_debug=True
)
backend_2 = QuantinuumBackend(
device_name, api_handler=handler_2, machine_debug=True
)

assert backend_1.api_handler is not backend_2.api_handler
assert backend_1.api_handler._cred_store is not backend_2.api_handler._cred_store

0 comments on commit e27e08b

Please sign in to comment.