Skip to content

Commit

Permalink
Add support for extra input parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec committed Jul 11, 2024
1 parent 397700b commit d65aef7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 53 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@ on:
pull_request:
branches:
- main
schedule:
# 04:00 every Tuesday morning
- cron: '0 4 * * 2'
workflow_dispatch: {}

env:
PYTKET_RUN_REMOTE_TESTS: 1
PYTKET_REMOTE_AZURE_RESOURCE_ID: ${{ secrets.PYTKET_REMOTE_AZURE_RESOURCE_ID }}
PYTKET_REMOTE_AZURE_LOCATION: ${{ secrets.PYTKET_REMOTE_AZURE_LOCATION }}
PYTKET_REMOTE_AZURE_STORAGE: ${{ secrets.PYTKET_REMOTE_AZURE_STORAGE }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}

jobs:
checks:
name: Build and test module
Expand All @@ -30,4 +24,17 @@ jobs:
python-version: '3.10'
- name: Build and test
shell: bash
run: ./.github/workflows/build-test nomypy
env:
PYTKET_RUN_REMOTE_TESTS: 1
PYTKET_REMOTE_AZURE_RESOURCE_ID: ${{ secrets.PYTKET_REMOTE_AZURE_RESOURCE_ID }}
PYTKET_REMOTE_AZURE_LOCATION: ${{ secrets.PYTKET_REMOTE_AZURE_LOCATION }}
PYTKET_REMOTE_AZURE_STORAGE: ${{ secrets.PYTKET_REMOTE_AZURE_STORAGE }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
run: ./.github/workflows/build-test mypy
- name: Install docs dependencies
run: pip install -r .github/workflows/docs/requirements.txt
- name: Build docs
timeout-minutes: 20
run: ./.github/workflows/docs/check-build-docs
36 changes: 0 additions & 36 deletions .github/workflows/full_checks.yml

This file was deleted.

20 changes: 15 additions & 5 deletions pytket/extensions/azure/backends/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,14 @@ def process_circuits(
) -> List[ResultHandle]:
"""
See :py:meth:`pytket.backends.Backend.process_circuits`.
Supported kwargs:
- option_params: a dictionary with string keys and arbitrary values;
key-value pairs in the dictionary are passed as input parameters to
the backend. Their semantics are backend-dependent.
"""
option_params = kwargs.get("option_params")
circuits = list(circuits)
n_shots_list = Backend._get_n_shots_as_list(
n_shots,
Expand All @@ -138,16 +145,19 @@ def process_circuits(
qkc = tk_to_qiskit(c)
module, entry_points = to_qir_module(qkc)
assert len(entry_points) == 1
input_params = {
"entryPoint": entry_points[0],
"arguments": [],
"count": n_shots,
}
if option_params is not None:
input_params.update(option_params)
job = self._target.submit(
input_data=module.bitcode,
input_data_format="qir.v1",
output_data_format="microsoft.quantum-results.v1",
name=f"job_{i}",
input_params={
"entryPoint": entry_points[0],
"arguments": [],
"count": n_shots,
},
input_params=input_params,
)
jobid: str = job.id
handle = ResultHandle(jobid)
Expand Down
24 changes: 22 additions & 2 deletions tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from collections import Counter
import os
from warnings import warn
import pytest
from pytket.circuit import Circuit
from pytket.extensions.azure import AzureBackend
Expand All @@ -33,16 +34,35 @@ def test_ionq_simulator(azure_backend: AzureBackend) -> None:
r = b.get_result(h)
counts = r.get_counts()
assert counts == Counter({(0, 0): 5, (1, 1): 5})
else:
warn("ionq.simulator unavailable or queue time >= 60s: not submitting")


@pytest.mark.skipif(skip_remote_tests, reason=REASON)
@pytest.mark.parametrize("azure_backend", ["quantinuum.sim.h1-1e"], indirect=True)
@pytest.mark.parametrize("azure_backend", ["quantinuum.sim.h1-1sc"], indirect=True)
def test_quantinuum_sim_h11e(azure_backend: AzureBackend) -> None:
c = Circuit(2).H(0).CX(0, 1).measure_all()
b = azure_backend
c1 = b.get_compiled_circuit(c)
if b.is_available() and b.average_queue_time_s() < 600:
if b.is_available() and b.average_queue_time_s() < 60:
h = b.process_circuit(c1, n_shots=1000)
r = b.get_result(h)
counts = r.get_counts()
assert sum(counts.values()) == 1000
else:
warn("quantinuum.sim.h1-1sc unavailable or queue time >= 60s: not submitting")


@pytest.mark.skipif(skip_remote_tests, reason=REASON)
@pytest.mark.parametrize("azure_backend", ["quantinuum.sim.h1-1e"], indirect=True)
def test_quantinuum_option_params(azure_backend: AzureBackend) -> None:
c = Circuit(2).H(0).CX(0, 1).measure_all()
b = azure_backend
c1 = b.get_compiled_circuit(c)
if b.is_available() and b.average_queue_time_s() < 600:
h = b.process_circuit(c1, n_shots=1000, option_params={"error_model": False})
r = b.get_result(h)
counts = r.get_counts()
assert all(x0 == x1 for x0, x1 in counts.keys())
else:
warn("quantinuum.sim.h1-1e unavailable or queue time >= 600s: not submitting")

0 comments on commit d65aef7

Please sign in to comment.