Skip to content

Fix e2e tests #675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 22, 2025
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
3 changes: 2 additions & 1 deletion azure-quantum/azure/quantum/cirq/targets/quantinuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
##
import json
import numpy as np

from typing import TYPE_CHECKING, Any, Dict, Sequence
Expand Down Expand Up @@ -97,7 +98,7 @@ def submit(
metadata = {
"qubits": len(program.all_qubits()),
"repetitions": repetitions,
"measurement_dict": self._measurement_dict(program)
"measurement_dict": json.dumps(self._measurement_dict(program))
}
# Override metadata with value from kwargs
metadata.update(kwargs.get("metadata", {}))
Expand Down
4 changes: 3 additions & 1 deletion azure-quantum/azure/quantum/qiskit/backends/ionq.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
if TYPE_CHECKING:
from azure.quantum.qiskit import AzureQuantumProvider

import json

import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -244,7 +246,7 @@ def _prepare_job_metadata(self, circuit, **kwargs):
_, _, meas_map = qiskit_circ_to_ionq_circ(circuit, gateset=self.gateset())

metadata = super()._prepare_job_metadata(circuit, **kwargs)
metadata["meas_map"] = meas_map
metadata["meas_map"] = json.dumps(meas_map)

return metadata

Expand Down
7 changes: 5 additions & 2 deletions azure-quantum/tests/unit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class RegexScrubbingPatterns:
URL_QUERY_AUTH_CLAIMS = r"claims=[\w\%\-\.]+"
URL_QUERY_AUTH_CODE_VERIFIER = r"code_verifier=[\w\%\-\.]+"
URL_QUERY_AUTH_CODE = r"code=[\w\%\-\.]+"
URL_QUERY_KEY_CODE = r"key=[\w\%\-\.]+"
URL_HTTP = r"http://" # Devskim: ignore DS137138

class QuantumTestBase(ReplayableTest):
Expand Down Expand Up @@ -180,6 +181,8 @@ def __init__(self, method_name):
"code_verifier=PLACEHOLDER")
self._regex_replacer.register_scrubbing(RegexScrubbingPatterns.URL_QUERY_AUTH_CODE,
"code=PLACEHOLDER")
self._regex_replacer.register_scrubbing(RegexScrubbingPatterns.URL_QUERY_KEY_CODE,
"key=PLACEHOLDER")
self._regex_replacer.register_scrubbing(RegexScrubbingPatterns.URL_HTTP, "https://")

self._regex_replacer.register_scrubbing(
Expand Down Expand Up @@ -318,14 +321,14 @@ def create_echo_target(
**kwargs
) -> Target:
"""
Create a `Microsoft.Test.echo-target` Target for simple job submission tests.
Create a `Microsoft.Test.FirstParty.echo-target` Target for simple job submission tests.
Uses the Workspace returned from `create_workspace()` method.
"""
workspace = self.create_workspace(credential=credential, **kwargs)
target = Target(
workspace=workspace,
name="echo-output",
provider_id="Microsoft.Test",
provider_id="Microsoft.Test.FirstParty",
input_data_format = "microsoft.quantum-log.v1",
output_data_format = "microsoft.quantum-log.v1"
)
Expand Down

Large diffs are not rendered by default.

1,708 changes: 1,490 additions & 218 deletions azure-quantum/tests/unit/recordings/test_dft_failure_invalid_input.yaml

Large diffs are not rendered by default.

858 changes: 476 additions & 382 deletions azure-quantum/tests/unit/recordings/test_dft_success.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions azure-quantum/tests/unit/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def test_workspace_auth_connection_string_api_key(self):
token = self._get_rp_credential()
workspace = self._get_workspace(token)
self._enable_workspace_api_keys(token, workspace, True)
time.sleep(10)
connection_string = self._get_current_primary_connection_string(token)
self.resume_recording()
# Sleep 1 min for cache to be cleared
Expand All @@ -351,8 +352,8 @@ def test_workspace_auth_connection_string_api_key(self):
workspace = Workspace.from_connection_string(
connection_string=connection_string,
)
jobs = workspace.list_jobs()
assert len(jobs) >= 0
jobs_paged = workspace.list_jobs_paginated()
assert jobs_paged.next() is not None

if not self.is_playback:
self.pause_recording()
Expand All @@ -369,6 +370,6 @@ def test_workspace_auth_connection_string_api_key(self):
connection_string=connection_string,
)
with self.assertRaises(Exception) as context:
workspace.list_jobs()
workspace.list_jobs_paginated().next()

self.assertIn("Unauthorized", context.exception.message)
39 changes: 10 additions & 29 deletions azure-quantum/tests/unit/test_microsoft_elements_dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ class TestMicrosoftElementsDftJob(QuantumTestBase):
@pytest.mark.microsoft_elements_dft
def test_dft_success(self):
dft_input_params = {
"tasks": [
{
"taskType": "spe",
"basisSet": { "name": "def2-svp", "cartesian": False },
"xcFunctional": { "name": "m06-2x", "gridLevel": 4 },
"scf": { "method": "rks", "maxSteps": 100, "convergeThreshold": 1e-8 }
}
]
"driver": "energy",
"model": {"method": "m06-2x", "basis": "def2-svp"},
}

job = self._run_job(dft_input_params)
Expand All @@ -37,14 +31,8 @@ def test_dft_success(self):
@pytest.mark.microsoft_elements_dft
def test_dft_failure_invalid_input(self):
dft_input_params = {
"tasks": [
{
"taskType": "invlidTask",
"basisSet": { "name": "def2-svp", "cartesian": False },
"xcFunctional": { "name": "m06-2x", "gridLevel": 4 },
"scf": { "method": "rks", "maxSteps": 100, "convergeThreshold": 1e-8 }
}
]
"driver": "energy",
"model": {"method": "m06-2x", "basis": "invalidBasis"},
}

job = self._run_job(dft_input_params)
Expand All @@ -58,14 +46,8 @@ def test_dft_failure_invalid_input(self):
@pytest.mark.microsoft_elements_dft
def test_dft_failure_algorithm_produces_output(self):
dft_input_params = {
"tasks": [
{
"taskType": "spe",
"basisSet": { "name": "def2-svp", "cartesian": False },
"xcFunctional": { "name": "m06-2x", "gridLevel": 4 },
"scf": { "method": "rks", "maxSteps": 1, "convergeThreshold": 1e-8 }
}
]
"driver": "energy",
"model": {"method": "m06-2x", "basis": "invalidBasis"},
}

job = self._run_job(dft_input_params)
Expand All @@ -82,12 +64,11 @@ def _run_job(self, input_params) -> Job:
target = workspace.get_targets("microsoft.dft")
dir_path = os.path.dirname(os.path.realpath(__file__))

with open(f"{dir_path}/molecule.xyz", "r") as file:
job = target.submit(input_data=file.read(), input_params=input_params)
job.wait_until_completed(timeout_secs=DEFAULT_TIMEOUT_SECS)
job.refresh()
job = target.submit(input_data=[f"{dir_path}/molecule.xyz"], input_params=input_params)
job.wait_until_completed(timeout_secs=DEFAULT_TIMEOUT_SECS)
job.refresh()

return job
return job

test_xyz_file = Path(__file__).parent / "molecule.xyz"

Expand Down
4 changes: 2 additions & 2 deletions azure-quantum/tests/unit/test_qiskit.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def test_qiskit_get_ionq_native_gateset(self):
self.assertEqual("native", payload["gateset"])
# We also expect the metadata to be produced correctly for native circuits
metadata = backend._prepare_job_metadata(native_circuit)
self.assertEqual(2, len(metadata["meas_map"]))
self.assertEqual(2,len(json.loads(metadata["meas_map"])))

# should also be available with the qpu target
backend = provider.get_backend("ionq.qpu.aria-1", gateset="native")
Expand All @@ -950,7 +950,7 @@ def test_qiskit_get_ionq_native_gateset(self):
payload = json.loads(payload.decode("utf-8"))
self.assertEqual("ms", payload["circuit"][0]["gate"])
metadata = backend._prepare_job_metadata(native_circuit)
self.assertEqual(2, len(metadata["meas_map"]))
self.assertEqual(2, len(json.loads(metadata["meas_map"])))

@pytest.mark.ionq
@pytest.mark.live_test
Expand Down
Loading