Skip to content
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

Add Pasqal support #511

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion azure-quantum/azure/quantum/target/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from .ionq import IonQ
from .quantinuum import Quantinuum
from .rigetti import Rigetti
from .pasqal import Pasqal

# Default targets to use when there is no target class
# associated with a given target ID
DEFAULT_TARGETS = {
"ionq": IonQ,
"quantinuum": Quantinuum,
"rigetti": Rigetti,
"toshiba": Solver
"toshiba": Solver,
"pasqal": Pasqal
}
16 changes: 16 additions & 0 deletions azure-quantum/azure/quantum/target/pasqal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Defines targets and helper functions for the Pasqal provider"""

##
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
##

__all__ = [
"InputParams",
"Result",
"Pasqal",
"PasqalTarget",
]

from .result import Result
from .target import InputParams, Pasqal, PasqalTarget
44 changes: 44 additions & 0 deletions azure-quantum/azure/quantum/target/pasqal/result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Defines targets and helper functions for the Pasqal provider"""

##
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
##

__all__ = [
"Result",
]

import json
from typing import Union, Dict, List, TypeVar, cast

from ...job import Job


class Result:
"""Downloads the data of a completed Job and provides a dictionary of registers.

>>> from azure.quantum.job import Job
>>> from azure.quantum.target.pasqal import Result
>>> job = Job(...) # This job should come from a Pasqal target
>>> job.wait_until_completed()
>>> result = Result(job)
"""

def __init__(self, job: Job) -> None:
"""
Decode the results of a Job with output type of "pasqal.pulser-results.v1"

:raises: RuntimeError if the job has not completed successfully
"""

if job.details.status != "Succeeded":
raise RuntimeError(
"Cannot retrieve results as job execution failed "
f"(status: {job.details.status}."
f"error: {job.details.error_data})"
)
self.data = cast(Dict[str, int], json.loads(job.download_data(job.details.output_data_uri)))

def __getitem__(self, register_name: str) -> int:
tncc marked this conversation as resolved.
Show resolved Hide resolved
return self.data[register_name]
121 changes: 121 additions & 0 deletions azure-quantum/azure/quantum/target/pasqal/target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""Defines targets and helper functions for the Pasqal provider"""

##
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
##

__all__ = [
"InputParams",
"Pasqal",
"PasqalTarget",
]

from dataclasses import dataclass
from enum import Enum
from typing import Union, Any, Dict, List, Optional

from ..target import Target
from ... import Job
from ...workspace import Workspace


class PasqalTarget(str, Enum):
"""The known targets for the Pasqal provider
"""

SIM = "pasqal.sim"
SIM_EMU_FREE = "pasqal.sim.emu_free"
SIM_EMU_TN = "pasqal.sim.emu_tn"
SIM_EMU_SV = "pasqal.sim.emu_sv"
QPU = "pasqal.qpu"
QPU_FRESNEL = "pasqal.qpu.fresnel"
"""A simulator target for Quil. See https://github.com/quil-lang/qvm for more info."""

def simulators() -> List[str]:
"""Returns a list of simulator targets"""
return [
PasqalTarget.SIM.value,
PasqalTarget.SIM_EMU_FREE.value,
PasqalTarget.SIM_EMU_TN.value,
PasqalTarget.SIM_EMU_SV.value,
]

def qpus() -> List[str]:
"""Returns a list of QPU targets"""
return [
PasqalTarget.QPU.value,
PasqalTarget.QPU_FRESNEL.value
]

def num_qubits(target_name) -> int:
"""Returns the number of qubits supported by the given target"""
if target_name == PasqalTarget.SIM.value:
return 20 # TODO temp value, need info from Pasqal
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved


@dataclass
class InputParams:
runs: int = 1
"""The number of times to run the experiment."""


class Pasqal(Target):
"""Pasqal target, defaults to the simulator PasqalTarget.SIM

In order to process the results of a Quil input to this target, we recommend using the included Result class.
"""

target_names = tuple(target.value for target in PasqalTarget)

def __init__(
self,
workspace: Workspace,
name: Union[PasqalTarget, str] = PasqalTarget.SIM,
input_data_format: str = "pasqal.pulser.v1",
output_data_format: str = "pasqal.pulser-results.v1",
capability: str = "BasicExecution",
provider_id: str = "pasqal",
encoding: str = "",
**kwargs,
):
super().__init__(
workspace=workspace,
name=name,
input_data_format=input_data_format,
output_data_format=output_data_format,
capability=capability,
provider_id=provider_id,
content_type="text/plain",
encoding=encoding,
**kwargs,
)

def submit(
self,
input_data: Any,
name: str = "azure-quantum-job",
input_params: Union[InputParams, None, Dict[str, Any]] = None,
**kwargs,
) -> Job:
"""Submit input data and return Job.

Provide input_data_format, output_data_format and content_type
keyword arguments to override default values.

:param input_data: Input data
:type input_data: Any
:param name: Job name
:type name: str
:param input_params: Input parameters, see :class:`azure.quantum.target.pasqal.InputParams` for details.
:type input_params: Union[InputParams, None, Dict[str, Any]]
:return: Azure Quantum job
:rtype: Job
"""
if isinstance(input_params, InputParams):
typed_input_params = input_params
input_params = {
"runs": typed_input_params.runs,
}

return super().submit(input_data, name, input_params, **kwargs)
3 changes: 3 additions & 0 deletions azure-quantum/tests.live/Run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function PyTestMarkExpr() {
if ($AzureQuantumCapabilities -notcontains "submit.rigetti") {
$MarkExpr += " and not rigetti"
}
if ($AzureQuantumCapabilities -notcontains "submit.pasqal") {
$MarkExpr += " and not pasqal"
}
if ($AzureQuantumCapabilities -notcontains "submit.quantinuum") {
$MarkExpr += " and not quantinuum"
}
Expand Down
Loading
Loading