Skip to content

Commit

Permalink
Merge branch 'main' into msoeken/readme
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyi-joffre authored Oct 24, 2023
2 parents 183c24d + f8e053b commit 49d80ed
Show file tree
Hide file tree
Showing 9 changed files with 2,637 additions and 1 deletion.
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:
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_EMU_FREE = "pasqal.sim.emu_free"
SIM_EMU_TN = "pasqal.sim.emu_tn"
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_EMU_FREE.value,
PasqalTarget.SIM_EMU_TN.value
]

def qpus() -> List[str]:
"""Returns a list of QPU targets"""
return [
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_EMU_FREE.value:
return 12
elif target_name == PasqalTarget.SIM_EMU_TN.value:
return 100
elif target_name == PasqalTarget.QPU_FRESNEL.value:
return 20
else:
raise ValueError(f"Unknown target {target_name}")


@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_EMU_FREE
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_EMU_FREE,
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

0 comments on commit 49d80ed

Please sign in to comment.