From c4a5c1036ad3e8d4493a566d21708db2822b19aa Mon Sep 17 00:00:00 2001 From: Ava Wang <57644099+avawang1@users.noreply.github.com> Date: Wed, 12 Aug 2020 17:06:36 -0700 Subject: [PATCH] change: remove braket regions in AwsSession as this is done in boto3 (#134) documentation: fix miscellaneous items in docs and add references --- doc/index.rst | 2 +- src/braket/annealing/problem.py | 6 +++--- src/braket/aws/aws_device.py | 6 +++++- src/braket/aws/aws_quantum_task.py | 3 --- src/braket/aws/aws_session.py | 11 ----------- src/braket/circuits/circuit_diagram.py | 2 +- src/braket/circuits/instruction.py | 2 +- src/braket/circuits/moments.py | 14 +++++++------- src/braket/circuits/observables.py | 2 +- src/braket/circuits/quantum_operator.py | 8 +++++--- src/braket/devices/device.py | 2 +- src/braket/devices/local_simulator.py | 12 ++++++++---- test/unit_tests/braket/aws/test_aws_session.py | 7 ------- 13 files changed, 33 insertions(+), 44 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index cfa6e2c0c..73bf96355 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -3,7 +3,7 @@ Amazon Braket Python SDK Amazon Braket Python SDK is an open source library for interacting with quantum devices on Amazon Braket. -This documentation provides information about the Amazon Braket Python SDK API. For information about how to configure your environment to use the braket-python-sdk, please see the README in the GitHub repo for this project at https://github.com/aws/amazon-braket-sdk-python. +This documentation provides information about the Amazon Braket Python SDK library. For information about how to configure your environment to use the amazon-braket-sdk, please see the README in the GitHub repo for this project at https://github.com/aws/amazon-braket-sdk-python. Indices and tables __________________ diff --git a/src/braket/annealing/problem.py b/src/braket/annealing/problem.py index 9d7d2be46..81de48ca2 100644 --- a/src/braket/annealing/problem.py +++ b/src/braket/annealing/problem.py @@ -21,7 +21,9 @@ class ProblemType(str, Enum): """ The type of annealing problem. + QUBO: Quadratic Unconstrained Binary Optimization, with values 1 and 0 + ISING: Ising model, with values +/-1 """ @@ -30,9 +32,7 @@ class ProblemType(str, Enum): class Problem: - """ Represents an annealing problem. - - """ + """ Represents an annealing problem.""" def __init__( self, diff --git a/src/braket/aws/aws_device.py b/src/braket/aws/aws_device.py index c23da3b49..b39195015 100644 --- a/src/braket/aws/aws_device.py +++ b/src/braket/aws/aws_device.py @@ -179,7 +179,11 @@ def arn(self) -> str: @property # TODO: Add a link to the boto3 docs def properties(self) -> DeviceCapabilities: - """DeviceCapabilities: Return the device properties""" + """DeviceCapabilities: Return the device properties + + Please see `braket.device_schema` in amazon-braket-schemas-python_ + + .. _amazon-braket-schemas-python: https://github.com/aws/amazon-braket-schemas-python""" return self._properties @property diff --git a/src/braket/aws/aws_quantum_task.py b/src/braket/aws/aws_quantum_task.py index 520c56dc5..6793d13b6 100644 --- a/src/braket/aws/aws_quantum_task.py +++ b/src/braket/aws/aws_quantum_task.py @@ -43,9 +43,6 @@ class AwsQuantumTask(QuantumTask): NO_RESULT_TERMINAL_STATES = {"FAILED", "CANCELLED"} RESULTS_READY_STATES = {"COMPLETED"} - GATE_IR_TYPE = "jaqcd" - ANNEALING_IR_TYPE = "annealing" - DEFAULT_RESULTS_POLL_TIMEOUT = 120 DEFAULT_RESULTS_POLL_INTERVAL = 0.25 RESULTS_FILENAME = "results.json" diff --git a/src/braket/aws/aws_session.py b/src/braket/aws/aws_session.py index 2ac310ef7..44eb68ec6 100644 --- a/src/braket/aws/aws_session.py +++ b/src/braket/aws/aws_session.py @@ -23,16 +23,11 @@ class AwsSession(object): S3DestinationFolder = NamedTuple("S3DestinationFolder", [("bucket", str), ("key", int)]) - BRAKET_REGIONS = ["us-east-1", "us-west-1", "us-west-2"] - def __init__(self, boto_session=None, braket_client=None): """ Args: boto_session: A boto3 session object braket_client: A boto3 Braket client - - Raises: - ValueError: If Braket is not available in the Region used for the boto3 session. """ self.boto_session = boto_session or boto3.Session() @@ -40,12 +35,6 @@ def __init__(self, boto_session=None, braket_client=None): if braket_client: self.braket_client = braket_client else: - region = self.boto_session.region_name - if region not in AwsSession.BRAKET_REGIONS: - raise ValueError( - f"No braket endpoint for {region}, " - + f"supported Regions are {AwsSession.BRAKET_REGIONS}" - ) self.braket_client = self.boto_session.client("braket") # diff --git a/src/braket/circuits/circuit_diagram.py b/src/braket/circuits/circuit_diagram.py index 821db691c..ad2fd7efd 100644 --- a/src/braket/circuits/circuit_diagram.py +++ b/src/braket/circuits/circuit_diagram.py @@ -28,5 +28,5 @@ def build_diagram(circuit) -> str: Returns: str: String representation for the circuit diagram. - An empty string is returned for an empty circuit. + An empty string is returned for an empty circuit. """ diff --git a/src/braket/circuits/instruction.py b/src/braket/circuits/instruction.py index 36c28153f..35c557823 100644 --- a/src/braket/circuits/instruction.py +++ b/src/braket/circuits/instruction.py @@ -41,7 +41,7 @@ def __init__(self, operator: InstructionOperator, target: QubitSetInput): ValueError: If `operator` is empty or any integer in `target` does not meet the `Qubit` or `QubitSet` class requirements. TypeError: If a `Qubit` class can't be constructed from `target` due to an incorrect - `typing`. + `typing`. Examples: >>> Instruction(Gate.CNot(), [0, 1]) diff --git a/src/braket/circuits/moments.py b/src/braket/circuits/moments.py index 5e44cd49d..c4b154a42 100644 --- a/src/braket/circuits/moments.py +++ b/src/braket/circuits/moments.py @@ -38,17 +38,17 @@ class MomentsKey(NamedTuple): class Moments(Mapping[MomentsKey, Instruction]): """ An ordered mapping of `MomentsKey` to `Instruction`. The core data structure that - contains instructions, ordering they are inserted in, and time slices when they - occur. `Moments` implements `Mapping` and functions the same as a read-only - dictionary. It is mutable only through the `add()` method. + contains instructions, ordering they are inserted in, and time slices when they + occur. `Moments` implements `Mapping` and functions the same as a read-only + dictionary. It is mutable only through the `add()` method. This data structure is useful to determine a dependency of instructions, such as - printing or optimizing circuit structure, before sending it to a quantum - device. The original insertion order is preserved and can be retrieved via the `values()` - method. + printing or optimizing circuit structure, before sending it to a quantum + device. The original insertion order is preserved and can be retrieved via the `values()` + method. Args: - instructions (Iterable[Instruction], optional): Instructions to initialize self with. + instructions (Iterable[Instruction], optional): Instructions to initialize self. Default = []. Examples: diff --git a/src/braket/circuits/observables.py b/src/braket/circuits/observables.py index 7cb748006..da6636458 100644 --- a/src/braket/circuits/observables.py +++ b/src/braket/circuits/observables.py @@ -273,7 +273,7 @@ def __init__(self, matrix: np.ndarray, display_name: str = "Hermitian"): or has a dimension length that is not a positive exponent of 2, or is non-hermitian. - Example: + Examples: >>> Observable.Hermitian(matrix=np.array([[0, 1],[1, 0]])) """ verify_quantum_operator_matrix_dimensions(matrix) diff --git a/src/braket/circuits/quantum_operator.py b/src/braket/circuits/quantum_operator.py index 047100417..8eaab89b9 100644 --- a/src/braket/circuits/quantum_operator.py +++ b/src/braket/circuits/quantum_operator.py @@ -10,6 +10,8 @@ # 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 __future__ import annotations + from typing import Any, List, Sequence import numpy as np @@ -86,12 +88,12 @@ def to_matrix(self, *args, **kwargs) -> Any: """ raise NotImplementedError("to_matrix has not been implemented yet.") - def matrix_equivalence(self, other): + def matrix_equivalence(self, other: QuantumOperator): """ - Whether the matrix form of two gates are equivalent + Whether the matrix form of two quantum operators are equivalent Args: - other (Gate): Gate instance to compare this quantum operator to + other (QuantumOperator): Quantum operator instance to compare this quantum operator to Returns: bool: If matrix forms of this quantum operator and the other quantum operator diff --git a/src/braket/devices/device.py b/src/braket/devices/device.py index 4c9395a21..fffaa357e 100644 --- a/src/braket/devices/device.py +++ b/src/braket/devices/device.py @@ -44,7 +44,7 @@ def run( task_specification (Union[Circuit, Problem]): Specification of a task to run on device. - shots (int): The number of times to run the task on the device. Default is 1_000. + shots (int): The number of times to run the task on the device. Default is `None`. Returns: QuantumTask: The QuantumTask tracking task execution on this device diff --git a/src/braket/devices/local_simulator.py b/src/braket/devices/local_simulator.py index fb0f32778..d6858f002 100644 --- a/src/braket/devices/local_simulator.py +++ b/src/braket/devices/local_simulator.py @@ -42,7 +42,7 @@ def __init__(self, backend: Union[str, BraketSimulator] = "default"): Args: backend (Union[str, BraketSimulator]): The name of the simulator backend or the actual simulator instance to use for simulation. Defaults to the - "default" simulator backend name. + `default` simulator backend name. """ delegate = _get_simulator(backend) super().__init__( @@ -61,8 +61,8 @@ def run( Default is 0, which means that the simulator will compute the exact results based on the task specification. Sampling is not supported for shots=0. - *args: Positional args to pass to the IR simulator - **kwargs: Keyword arguments to pass to the IR simulator + *args: Positional args to pass to the `BraketSimulator` + **kwargs: Keyword arguments to pass to the `BraketSimulator` Returns: LocalQuantumTask: A LocalQuantumTask object containing the results @@ -82,7 +82,11 @@ def run( @property def properties(self) -> DeviceCapabilities: - """ DeviceCapabilities: Properties of the LocalSimulator device """ + """DeviceCapabilities: Return the device properties + + Please see `braket.device_schema` in amazon-braket-schemas-python_ + + .. _amazon-braket-schemas-python: https://github.com/aws/amazon-braket-schemas-python""" return self._delegate.properties @staticmethod diff --git a/test/unit_tests/braket/aws/test_aws_session.py b/test/unit_tests/braket/aws/test_aws_session.py index 8867e68d2..a452d2db5 100644 --- a/test/unit_tests/braket/aws/test_aws_session.py +++ b/test/unit_tests/braket/aws/test_aws_session.py @@ -34,13 +34,6 @@ def aws_session(boto_session): return AwsSession(boto_session=boto_session, braket_client=Mock()) -@pytest.mark.xfail(raises=ValueError) -def test_no_endpoint_for_region(): - boto_session = Mock() - boto_session.region_name = "foobar" - AwsSession(boto_session=boto_session, braket_client=None) - - def test_initializes_boto_client_if_required(boto_session): AwsSession(boto_session=boto_session, braket_client=None) boto_session.client.assert_called_with("braket")