-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into msoeken/readme
- Loading branch information
Showing
9 changed files
with
2,637 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.