Skip to content

Commit 201aec8

Browse files
authored
doc: Use idiomatic Python types in docstrings (#1151)
1 parent c13c1c6 commit 201aec8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+480
-489
lines changed

src/braket/ahs/atom_arrangement.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def add(
7070
"""Add a coordinate to the atom arrangement.
7171
7272
Args:
73-
coordinate (Union[tuple[Number, Number], ndarray]): The coordinate of the
73+
coordinate (tuple[Number, Number] | np.ndarray): The coordinate of the
7474
atom (in meters). The coordinates can be a numpy array of shape (2,)
7575
or a tuple of int, float, Decimal
7676
site_type (SiteType): The type of site. Optional. Default is FILLED.
@@ -354,7 +354,7 @@ def from_bravais_lattice(
354354
a1 (tuple[Number, Number]): First lattice vector (x, y) in meters.
355355
a2 (tuple[Number, Number]): Second lattice vector (x, y) in meters.
356356
canvas (Canvas): Canvas defining the boundary where atoms can be placed.
357-
basis (list[tuple[Number, Number]], optional): Basis vectors for decorated lattice.
357+
basis (list[tuple[Number, Number]] | None): Basis vectors for decorated lattice.
358358
If None, uses a single atom at (0, 0). Default is None.
359359
site_type (SiteType): The type of sites to create. Default is FILLED.
360360

src/braket/ahs/driving_field.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def __init__(
5050
with the sum :math:`\sum_k` taken over all target atoms.
5151
5252
Args:
53-
amplitude (Union[Field, TimeSeries]): global amplitude (:math:`\Omega(t)`).
53+
amplitude (Field | TimeSeries): global amplitude (:math:`\Omega(t)`).
5454
Time is in s, and value is in rad/s.
55-
phase (Union[Field, TimeSeries]): global phase (:math:`\phi(t)`).
55+
phase (Field | TimeSeries): global phase (:math:`\phi(t)`).
5656
Time is in s, and value is in rad/s.
57-
detuning (Union[Field, TimeSeries]): global detuning (:math:`\Delta(t)`).
57+
detuning (Field | TimeSeries): global detuning (:math:`\Delta(t)`).
5858
Time is in s, and value is in rad/s.
5959
"""
6060
super().__init__()

src/braket/ahs/field.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, time_series: TimeSeries, pattern: Pattern | None = None) -> N
2525
2626
Args:
2727
time_series (TimeSeries): The time series representing this field.
28-
pattern (Optional[Pattern]): The local pattern of real numbers.
28+
pattern (Pattern | None): The local pattern of real numbers.
2929
"""
3030
self._time_series = time_series
3131
self._pattern = pattern
@@ -37,7 +37,7 @@ def time_series(self) -> TimeSeries:
3737

3838
@property
3939
def pattern(self) -> Pattern | None:
40-
"""Optional[Pattern]: The local pattern of real numbers."""
40+
"""Pattern | None: The local pattern of real numbers."""
4141
return self._pattern
4242

4343
def discretize(
@@ -51,9 +51,9 @@ def discretize(
5151
closest multiple of their corresponding resolutions.
5252
5353
Args:
54-
time_resolution (Optional[Decimal]): Time resolution
55-
value_resolution (Optional[Decimal]): Value resolution
56-
pattern_resolution (Optional[Decimal]): Pattern resolution
54+
time_resolution (Decimal | None): Time resolution
55+
value_resolution (Decimal | None): Value resolution
56+
pattern_resolution (Decimal | None): Pattern resolution
5757
5858
Returns:
5959
Field: A new discretized field.

src/braket/ahs/pattern.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def discretize(self, resolution: Decimal | None) -> Pattern:
4040
of the resolution.
4141
4242
Args:
43-
resolution (Optional[Decimal]): Resolution of the discretization
43+
resolution (Decimal | None): Resolution of the discretization
4444
4545
Returns:
4646
Pattern: The new discretized pattern

src/braket/aws/aws_device.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ def __init__(
9292
9393
Args:
9494
arn (str): The ARN of the device
95-
aws_session (Optional[AwsSession]): An AWS session object. Default is `None`.
96-
noise_model (Optional[NoiseModel]): The Braket noise model to apply to the circuit
95+
aws_session (AwsSession | None): An AWS session object. Default is `None`.
96+
noise_model (NoiseModel | None): The Braket noise model to apply to the circuit
9797
before execution. Noise model can only be added to the devices that support
9898
noise simulation.
9999
@@ -142,20 +142,20 @@ def run(
142142
task_specification (TaskSpecification):
143143
Specification of quantum task (circuit, OpenQASM program, program set,
144144
pulse sequence or AHS program) to run on the device.
145-
s3_destination_folder (Optional[S3DestinationFolder]): The S3 location to
145+
s3_destination_folder (S3DestinationFolder | None): The S3 location to
146146
save the quantum task's results to. Default is `<default_bucket>/tasks` if evoked outside a
147147
Braket Hybrid Job, `<Job Bucket>/jobs/<job name>/tasks` if evoked inside a Braket Hybrid Job.
148-
shots (Optional[int]): The number of times to run the circuit or annealing problem.
148+
shots (int | None): The number of times to run the circuit or annealing problem.
149149
Default is 1000 for QPUs and 0 for simulators.
150150
poll_timeout_seconds (float): The polling timeout for `AwsQuantumTask.result()`,
151151
in seconds. Default: 5 days.
152-
poll_interval_seconds (Optional[float]): The polling interval for `AwsQuantumTask.result()`,
152+
poll_interval_seconds (float | None): The polling interval for `AwsQuantumTask.result()`,
153153
in seconds. Defaults to the ``getTaskPollIntervalMillis`` value specified in
154154
``self.properties.service`` (divided by 1000) if provided, otherwise 1 second.
155-
inputs (Optional[dict[str, float]]): Inputs to be passed along with the
155+
inputs (dict[str, float] | None): Inputs to be passed along with the
156156
IR. If the IR supports inputs, the inputs will be updated with this value.
157157
Default: {}.
158-
gate_definitions (Optional[dict[tuple[Gate, QubitSet], PulseSequence]]): A
158+
gate_definitions (dict[tuple[Gate, QubitSet], PulseSequence] | None): A
159159
`dict[tuple[Gate, QubitSet], PulseSequence]]` for a user defined gate calibration.
160160
The calibration is defined for a particular `Gate` on a particular `QubitSet`
161161
and is represented by a `PulseSequence`.
@@ -244,12 +244,12 @@ def run_batch(
244244
task_specifications (TaskSpecification | list[TaskSpecification]):
245245
Single instance or list of task specifications (circuits, OpenQASM programs,
246246
pulse sequences or AHS programs) to run on the device.
247-
s3_destination_folder (Optional[S3DestinationFolder]): The S3 location to
247+
s3_destination_folder (S3DestinationFolder | None): The S3 location to
248248
save the quantum tasks' results to. Default is `<default_bucket>/tasks` if evoked outside a
249249
Braket Job, `<Job Bucket>/jobs/<job name>/tasks` if evoked inside a Braket Job.
250-
shots (Optional[int]): The number of times to run the circuit or annealing problem.
250+
shots (int | None): The number of times to run the circuit or annealing problem.
251251
Default is 1000 for QPUs and 0 for simulators.
252-
max_parallel (Optional[int]): The maximum number of quantum tasks to run on AWS in parallel.
252+
max_parallel (int | None): The maximum number of quantum tasks to run on AWS in parallel.
253253
Batch creation will fail if this value is greater than the maximum allowed
254254
concurrent quantum tasks on the device. Default: 10
255255
max_connections (int): The maximum number of connections in the Boto3 connection pool.
@@ -259,14 +259,14 @@ def run_batch(
259259
poll_interval_seconds (float): The polling interval for `AwsQuantumTask.result()`,
260260
in seconds. Defaults to the ``getTaskPollIntervalMillis`` value specified in
261261
``self.properties.service`` (divided by 1000) if provided, otherwise 1 second.
262-
inputs (Optional[dict[str, float] | list[dict[str, float]]]): Inputs to be
262+
inputs (dict[str, float] | list[dict[str, float]] | None): Inputs to be
263263
passed along with the IR. If the IR supports inputs, the inputs will be updated
264264
with this value. Default: {}.
265-
gate_definitions (Optional[dict[tuple[Gate, QubitSet], PulseSequence]]): A
265+
gate_definitions (dict[tuple[Gate, QubitSet], PulseSequence] | None): A
266266
`dict[tuple[Gate, QubitSet], PulseSequence]]` for a user defined gate calibration.
267267
The calibration is defined for a particular `Gate` on a particular `QubitSet`
268268
and is represented by a `PulseSequence`. Default: None.
269-
reservation_arn (Optional[str]): The reservation ARN provided by Braket Direct
269+
reservation_arn (str | None): The reservation ARN provided by Braket Direct
270270
to reserve exclusive usage for the device to run the quantum task on.
271271
Note: If you are creating tasks in a job that itself was created reservation ARN,
272272
those tasks do not need to be created with the reservation ARN.
@@ -409,7 +409,7 @@ def gate_calibrations(self) -> GateCalibrations | None:
409409
If a QPU does not expose these calibrations, None is returned.
410410
411411
Returns:
412-
Optional[GateCalibrations]: The calibration object. Returns `None` if the data
412+
GateCalibrations | None: The calibration object. Returns `None` if the data
413413
is not present.
414414
"""
415415
if not self._gate_calibrations:
@@ -610,18 +610,18 @@ def get_devices(
610610
>>> AwsDevice.get_devices(types=["SIMULATOR"])
611611
612612
Args:
613-
arns (Optional[list[str]]): device ARN filter, default is `None`
614-
names (Optional[list[str]]): device name filter, default is `None`
615-
types (Optional[list[AwsDeviceType]]): device type filter, default is `None`
613+
arns (list[str] | None): device ARN filter, default is `None`
614+
names (list[str] | None): device name filter, default is `None`
615+
types (list[AwsDeviceType] | None): device type filter, default is `None`
616616
QPUs will be searched for all regions and simulators will only be
617617
searched for the region of the current session.
618-
statuses (Optional[list[str]]): device status filter, default is `None`. When `None`
618+
statuses (list[str] | None): device status filter, default is `None`. When `None`
619619
is used, RETIRED devices will not be returned. To include RETIRED devices in
620620
the results, use a filter that includes "RETIRED" for this parameter.
621-
provider_names (Optional[list[str]]): provider name filter, default is `None`
621+
provider_names (list[str] | None): provider name filter, default is `None`
622622
order_by (str): field to order result by, default is `name`.
623623
Accepted values are ['arn', 'name', 'type', 'provider_name', 'status']
624-
aws_session (Optional[AwsSession]): An AWS session object.
624+
aws_session (AwsSession | None): An AWS session object.
625625
Default is `None`.
626626
627627
Raises:
@@ -782,7 +782,7 @@ def refresh_gate_calibrations(self) -> GateCalibrations | None:
782782
URLError: If the URL provided returns a non 2xx response.
783783
784784
Returns:
785-
Optional[GateCalibrations]: the calibration data for the device. None
785+
GateCalibrations | None: the calibration data for the device. None
786786
is returned if the device does not have a gate calibrations URL associated.
787787
"""
788788
if (

src/braket/aws/aws_quantum_task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def __init__(
245245
`getLogger(__name__)`
246246
quiet (bool): Sets the verbosity of the logger to low and does not report queue
247247
position. Default is `False`.
248-
task_specification (Optional[TaskSpecification]): The specification the task
248+
task_specification (TaskSpecification | None): The specification the task
249249
was run with
250250
251251
Examples:

src/braket/aws/aws_session.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,13 @@ def search_devices(
648648
all the filters `arns`, `names`, `types`, `statuses`, `provider_names`.
649649
650650
Args:
651-
arns (Optional[list[str]]): device ARN filter, default is `None`.
652-
names (Optional[list[str]]): device name filter, default is `None`.
653-
types (Optional[list[str]]): device type filter, default is `None`.
654-
statuses (Optional[list[str]]): device status filter, default is `None`. When `None`
651+
arns (list[str] | None): device ARN filter, default is `None`.
652+
names (list[str] | None): device name filter, default is `None`.
653+
types (list[str] | None): device type filter, default is `None`.
654+
statuses (list[str] | None): device status filter, default is `None`. When `None`
655655
is used, RETIRED devices will not be returned. To include RETIRED devices in
656656
the results, use a filter that includes "RETIRED" for this parameter.
657-
provider_names (Optional[list[str]]): provider name list, default is `None`.
657+
provider_names (list[str] | None): provider name list, default is `None`.
658658
659659
Returns:
660660
list[dict[str, Any]]: The response from the Amazon Braket `SearchDevices` operation.
@@ -755,9 +755,9 @@ def describe_log_streams(
755755
Args:
756756
log_group (str): Name of the log group.
757757
log_stream_prefix (str): Prefix for log streams to include.
758-
limit (Optional[int]): Limit for number of log streams returned.
758+
limit (int | None): Limit for number of log streams returned.
759759
default is 50.
760-
next_token (Optional[str]): The token for the next set of items to return.
760+
next_token (str | None): The token for the next set of items to return.
761761
Would have been received in a previous call.
762762
763763
Returns:
@@ -793,7 +793,7 @@ def get_log_events(
793793
start_time (int): Timestamp that indicates a start time to include log events.
794794
start_from_head (bool): Bool indicating to return oldest events first. default
795795
is True.
796-
next_token (Optional[str]): The token for the next set of items to return.
796+
next_token (str | None): The token for the next set of items to return.
797797
Would have been received in a previous call.
798798
799799
Returns:
@@ -819,8 +819,8 @@ def copy_session(
819819
"""Creates a new AwsSession based on the region.
820820
821821
Args:
822-
region (Optional[str]): Name of the region. Default = `None`.
823-
max_connections (Optional[int]): The maximum number of connections in the
822+
region (str | None): Name of the region. Default = `None`.
823+
max_connections (int | None): The maximum number of connections in the
824824
Boto3 connection pool. Default = `None`.
825825
826826
Returns:

src/braket/aws/queue_information.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class QuantumTaskQueueInfo:
5151
Attributes:
5252
queue_type (QueueType): type of the quantum_task queue either 'Normal'
5353
or 'Priority'.
54-
queue_position (Optional[str]): current position of your quantum task within a respective
54+
queue_position (str | None): current position of your quantum task within a respective
5555
device queue. This value can be None based on the state of the task. Default: None.
56-
message (Optional[str]): Additional message information. This key is present only
56+
message (str | None): Additional message information. This key is present only
5757
if 'queue_position' is None. Default: None.
5858
"""
5959

@@ -67,12 +67,12 @@ class HybridJobQueueInfo:
6767
"""Represents hybrid job queue information.
6868
6969
Attributes:
70-
queue_position (Optional[str]): current position of your hybrid job within a respective
70+
queue_position (str | None): current position of your hybrid job within a respective
7171
device queue. If the queue position of the hybrid job is greater than 15, we
7272
return '>15' as the queue_position return value. The queue_position is only
7373
returned when hybrid job is not in RUNNING/CANCELLING/TERMINAL states, else
7474
queue_position is returned as None.
75-
message (Optional[str]): Additional message information. This key is present only
75+
message (str | None): Additional message information. This key is present only
7676
if 'queue_position' is None. Default: None.
7777
"""
7878

0 commit comments

Comments
 (0)