Skip to content

Commit

Permalink
feat: add iqm schemas (#177)
Browse files Browse the repository at this point in the history

Co-authored-by: Coull <[email protected]>
  • Loading branch information
AbeCoull and Coull authored May 22, 2024
1 parent 244ffd5 commit 67f123e
Show file tree
Hide file tree
Showing 13 changed files with 1,193 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/braket/device_schema/iqm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License

from braket.device_schema.iqm.iqm_device_capabilities_v1 import IqmDeviceCapabilities # noqa: F401
from braket.device_schema.iqm.iqm_device_parameters_v1 import IqmDeviceParameters # noqa: F401
from braket.device_schema.iqm.iqm_provider_properties_v1 import IqmProviderProperties # noqa: F401
56 changes: 56 additions & 0 deletions src/braket/device_schema/iqm/iqm_device_capabilities_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License

from typing import Dict, Optional, Union

from pydantic.v1 import Field

from braket.device_schema.device_action_properties import DeviceActionType
from braket.device_schema.device_capabilities import DeviceCapabilities
from braket.device_schema.gate_model_qpu_paradigm_properties_v1 import (
GateModelQpuParadigmProperties,
)
from braket.device_schema.iqm.iqm_provider_properties_v1 import IqmProviderProperties
from braket.device_schema.openqasm_device_action_properties import OpenQASMDeviceActionProperties
from braket.device_schema.standardized_gate_model_qpu_device_properties_v1 import (
StandardizedGateModelQpuDeviceProperties,
)
from braket.schema_common.schema_base import BraketSchemaBase
from braket.schema_common.schema_header import BraketSchemaHeader


class IqmDeviceCapabilities(BraketSchemaBase, DeviceCapabilities):
"""
This defines the capabilities of an IQM device.
Attributes:
action(Dict[Union[DeviceActionType, str],
Union[OpenQASMDeviceActionProperties]]): Actions that an IQM device can support
paradigm(GateModelQpuParadigmProperties): Paradigm properties
provider(Optional[IqmProviderProperties]): IQM provider specific properties
standardized
(StandardizedGateModelQpuDeviceProperties): Braket standarized device
properties for IQM
"""

_PROGRAM_HEADER = BraketSchemaHeader(
name="braket.device_schema.iqm.iqm_device_capabilities", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
action: Dict[
Union[DeviceActionType, str],
Union[OpenQASMDeviceActionProperties],
]
paradigm: GateModelQpuParadigmProperties
provider: Optional[IqmProviderProperties]
standardized: Optional[StandardizedGateModelQpuDeviceProperties]
33 changes: 33 additions & 0 deletions src/braket/device_schema/iqm/iqm_device_parameters_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License

from pydantic.v1 import Field

from braket.device_schema.gate_model_parameters_v1 import GateModelParameters
from braket.schema_common.schema_base import BraketSchemaBase
from braket.schema_common.schema_header import BraketSchemaHeader


class IqmDeviceParameters(BraketSchemaBase):
"""
This defines the parameters common to all the IQM devices.
Attributes:
paradigmParameters: Parameters that are common to gatemodel paradigm
"""

_PROGRAM_HEADER = BraketSchemaHeader(
name="braket.device_schema.iqm.iqm_device_parameters", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
paradigmParameters: GateModelParameters
41 changes: 41 additions & 0 deletions src/braket/device_schema/iqm/iqm_provider_properties_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License

from typing import Dict, List, TypeVar, Union

from pydantic.v1 import Field

from braket.schema_common.schema_base import BraketSchemaBase
from braket.schema_common.schema_header import BraketSchemaHeader

GateFidelityType = TypeVar("GateFidelityType", bound=Dict[str, Union[str, float]])
OneQubitType = TypeVar("OneQubitType", bound=Union[float, List[GateFidelityType]])
TwoQubitType = TypeVar("TwoQubitType", bound=Dict[str, Union[float, Dict[str, int]]])

QubitType = TypeVar("QubitType", bound=Dict[str, Union[OneQubitType, TwoQubitType]])


class IqmProviderProperties(BraketSchemaBase):
"""
This defines the properties common to all the IQM devices.
Attributes:
properties (Dict[str, Dict[str, QubitType]]): Basic specifications for
the device, such as gate fidelities and coherence times.
"""

_PROGRAM_HEADER = BraketSchemaHeader(
name="braket.device_schema.iqm.iqm_provider_properties", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
properties: Dict[str, Dict[str, QubitType]]
3 changes: 3 additions & 0 deletions src/braket/task_result/additional_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from braket.ir.openqasm import Program as OpenQASMProgram
from braket.task_result.dwave_metadata_v1 import DwaveMetadata
from braket.task_result.ionq_metadata_v1 import IonQMetadata
from braket.task_result.iqm_metadata_v1 import IqmMetadata
from braket.task_result.oqc_metadata_v1 import OqcMetadata
from braket.task_result.quera_metadata_v1 import QueraMetadata
from braket.task_result.rigetti_metadata_v1 import RigettiMetadata
Expand Down Expand Up @@ -49,6 +50,7 @@ class AdditionalMetadata(BaseModel):
devices. Default: None.
simulatorMetadata (Optional[SimulatorQMetadata): Additional metadata for tasks that ran on
simulator devices. Default: None.
iqmMetadata (Optional[IqmMetadata): Additional metadata for tasks that ran on IQM.
Examples:
>>> AdditionalMetadata(action=OpenQASMProgram(source='OPENQASM3.0; cx $0, $1'))
Expand All @@ -62,3 +64,4 @@ class AdditionalMetadata(BaseModel):
xanaduMetadata: Optional[XanaduMetadata]
queraMetadata: Optional[QueraMetadata]
simulatorMetadata: Optional[SimulatorMetadata]
iqmMetadata: Optional[IqmMetadata]
34 changes: 34 additions & 0 deletions src/braket/task_result/iqm_metadata_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License

from pydantic.v1 import Field, constr

from braket.schema_common import BraketSchemaBase, BraketSchemaHeader


class IqmMetadata(BraketSchemaBase):
"""
The IQM metadata result schema.
Attributes:
braketSchemaHeader (BraketSchemaHeader): Schema header.
Users do not need to set this value. Only default is allowed.
compiledProgram (str): The program executed on the QPU.
"""

_IQM_METADATA_HEADER = BraketSchemaHeader(name="braket.task_result.iqm_metadata", version="1")
braketSchemaHeader: BraketSchemaHeader = Field(
default=_IQM_METADATA_HEADER, const=_IQM_METADATA_HEADER
)

compiledProgram: constr(min_length=2)
5 changes: 4 additions & 1 deletion src/braket/task_result/task_metadata_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DwaveDeviceParameters,
)
from braket.device_schema.ionq import IonqDeviceParameters
from braket.device_schema.iqm import IqmDeviceParameters
from braket.device_schema.oqc import OqcDeviceParameters
from braket.device_schema.rigetti import RigettiDeviceParameters
from braket.device_schema.simulators import GateModelSimulatorDeviceParameters
Expand All @@ -40,7 +41,8 @@ class TaskMetadata(BraketSchemaBase):
deviceId (str): The ID of the device on which the task ran.
For AWS devices, this is the device ARN.
deviceParameters any of (DwaveDeviceParameters, RigettiDeviceParameters,
IonqDeviceParameters, GateModelSimulatorDeviceParameters, XanaduDeviceParameters).
IonqDeviceParameters, GateModelSimulatorDeviceParameters, XanaduDeviceParameters,
IqmDeviceParameters).
The device parameters of the task. Default is None.
createdAt (str): The timestamp of creation;
the format must be in ISO-8601/RFC3339 string format YYYY-MM-DDTHH:mm:ss.sssZ.
Expand Down Expand Up @@ -74,6 +76,7 @@ class TaskMetadata(BraketSchemaBase):
OqcDeviceParameters,
GateModelSimulatorDeviceParameters,
XanaduDeviceParameters,
IqmDeviceParameters,
]
]
createdAt: Optional[constr(min_length=1, max_length=24)]
Expand Down
Loading

0 comments on commit 67f123e

Please sign in to comment.