Skip to content

Commit

Permalink
change: remove braket regions in AwsSession as this is done in boto3 (#…
Browse files Browse the repository at this point in the history
…134)

documentation: fix miscellaneous items in docs and add references
  • Loading branch information
avawang1 authored Aug 13, 2020
1 parent 369852d commit c4a5c10
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 44 deletions.
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
__________________
Expand Down
6 changes: 3 additions & 3 deletions src/braket/annealing/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand All @@ -30,9 +32,7 @@ class ProblemType(str, Enum):


class Problem:
""" Represents an annealing problem.
"""
""" Represents an annealing problem."""

def __init__(
self,
Expand Down
6 changes: 5 additions & 1 deletion src/braket/aws/aws_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/braket/aws/aws_quantum_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 0 additions & 11 deletions src/braket/aws/aws_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,18 @@ 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()

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")

#
Expand Down
2 changes: 1 addition & 1 deletion src/braket/circuits/circuit_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
2 changes: 1 addition & 1 deletion src/braket/circuits/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
14 changes: 7 additions & 7 deletions src/braket/circuits/moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/braket/circuits/observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/braket/circuits/quantum_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/braket/devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/braket/devices/local_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions test/unit_tests/braket/aws/test_aws_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c4a5c10

Please sign in to comment.