Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infra: drop support for Python 3.9 #1031

Open
wants to merge 2 commits into
base: ruff_test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
python-version: '3.9'
python-version: '3.10'
- name: Install dependencies
run: |
pip install tox
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependent-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11"]
dependent:
- amazon-braket-pennylane-plugin-python

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ formats:
build:
os: ubuntu-22.04
tools:
python: "3.9"
python: "3.10"

# Optionally set the version of Python and requirements required to build your docs
python:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The Amazon Braket Python SDK is an open source library that provides a framework
## Prerequisites
Before you begin working with the Amazon Braket SDK, make sure that you've installed or configured the following prerequisites.

### Python 3.9 or greater
Download and install Python 3.9 or greater from [Python.org](https://www.python.org/downloads/).
### Python 3.10 or greater
Download and install Python 3.10 or greater from [Python.org](https://www.python.org/downloads/).

### Git
Install Git from https://git-scm.com/downloads. Installation instructions are provided on the download page.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.ruff]
target-version = "py39"
target-version = "py310"
line-length = 100
format.preview = true
format.docstring-code-line-length = 100
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
name="amazon-braket-sdk",
version=version,
license="Apache License 2.0",
python_requires=">= 3.9",
python_requires=">= 3.10",
packages=find_namespace_packages(where="src", exclude=("test",)),
package_dir={"": "src"},
install_requires=[
Expand Down Expand Up @@ -78,7 +78,6 @@
"Natural Language :: English",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
Expand Down
4 changes: 3 additions & 1 deletion src/braket/ahs/analog_hamiltonian_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def from_ir(source: ir.Program) -> AnalogHamiltonianSimulation:
AnalogHamiltonianSimulation: The Analog Hamiltonian Simulation.
"""
atom_arrangement = AtomArrangement()
for site, fill in zip(source.setup.ahs_register.sites, source.setup.ahs_register.filling):
for site, fill in zip(
source.setup.ahs_register.sites, source.setup.ahs_register.filling, strict=False
):
atom_arrangement.add(
coordinate=site, site_type=SiteType.FILLED if fill == 1 else SiteType.VACANT
)
Expand Down
2 changes: 1 addition & 1 deletion src/braket/ahs/driving_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def from_lists(
phase = TimeSeries()

for t, amplitude_value, detuning_value, phase_value in zip(
times, amplitudes, detunings, phases
times, amplitudes, detunings, phases, strict=False
):
amplitude.put(t, amplitude_value)
detuning.put(t, detuning_value)
Expand Down
2 changes: 1 addition & 1 deletion src/braket/ahs/local_detuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def from_lists(times: list[float], values: list[float], pattern: list[float]) ->
raise ValueError("The length of the times and values lists must be equal.")

magnitude = TimeSeries()
for t, v in zip(times, values):
for t, v in zip(times, values, strict=False):
magnitude.put(t, v)
return LocalDetuning(Field(magnitude, Pattern(pattern)))

Expand Down
24 changes: 12 additions & 12 deletions src/braket/aws/aws_quantum_task_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,7 @@ def _tasks_inputs_gatedefs(
gate_definitions = gate_definitions or {}

single_task_type = (
Circuit,
Problem,
OpenQasmProgram,
BlackbirdProgram,
AnalogHamiltonianSimulation,
Circuit | Problem | OpenQasmProgram | BlackbirdProgram | AnalogHamiltonianSimulation
)
single_input_type = dict
single_gate_definitions_type = dict
Expand All @@ -186,7 +182,7 @@ def _tasks_inputs_gatedefs(

batch_length = 1
arg_lengths = []
for arg, single_arg_type in zip(args, single_arg_types):
for arg, single_arg_type in zip(args, single_arg_types, strict=False):
arg_length = 1 if isinstance(arg, single_arg_type) else len(arg)
arg_lengths.append(arg_length)

Expand All @@ -199,10 +195,10 @@ def _tasks_inputs_gatedefs(
batch_length = arg_length

for i in range(len(arg_lengths)):
if isinstance(args[i], (dict, single_task_type)):
if isinstance(args[i], (dict | single_task_type)):
args[i] = repeat(args[i], batch_length)

tasks_inputs_definitions = list(zip(*args))
tasks_inputs_definitions = list(zip(*args, strict=False))

for task_specification, input_map, _gate_definitions in tasks_inputs_definitions:
if isinstance(task_specification, Circuit):
Expand Down Expand Up @@ -352,7 +348,9 @@ def results(
if not self._results or not use_cached_value:
self._results = AwsQuantumTaskBatch._retrieve_results(self._tasks, self._max_workers)
self._unsuccessful = {
task.id for task, result in zip(self._tasks, self._results) if not result
task.id
for task, result in zip(self._tasks, self._results, strict=False)
if not result
}

retries = 0
Expand Down Expand Up @@ -402,14 +400,16 @@ def retry_unsuccessful_tasks(self) -> bool:
*self._aws_quantum_task_args,
**self._aws_quantum_task_kwargs,
)
for index, task in zip(unsuccessful_indices, retried_tasks):
for index, task in zip(unsuccessful_indices, retried_tasks, strict=False):
self._tasks[index] = task

retried_results = AwsQuantumTaskBatch._retrieve_results(retried_tasks, self._max_workers)
for index, result in zip(unsuccessful_indices, retried_results):
for index, result in zip(unsuccessful_indices, retried_results, strict=False):
self._results[index] = result
self._unsuccessful = {
task.id for task, result in zip(retried_tasks, retried_results) if not result
task.id
for task, result in zip(retried_tasks, retried_results, strict=False)
if not result
}
return not self._unsuccessful

Expand Down
9 changes: 4 additions & 5 deletions src/braket/aws/queue_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from dataclasses import dataclass
from enum import Enum
from typing import Optional


class QueueType(str, Enum):
Expand Down Expand Up @@ -59,8 +58,8 @@ class QuantumTaskQueueInfo:
"""

queue_type: QueueType
queue_position: Optional[str] = None
message: Optional[str] = None
queue_position: str | None = None
message: str | None = None


@dataclass
Expand All @@ -77,5 +76,5 @@ class HybridJobQueueInfo:
if 'queue_position' is None. Default: None.
"""

queue_position: Optional[str] = None
message: Optional[str] = None
queue_position: str | None = None
message: str | None = None
4 changes: 2 additions & 2 deletions src/braket/circuits/angled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def angled_ascii_characters(gate: str, angle: FreeParameterExpression | float) -
str: Returns the ascii representation for an angled gate.

"""
return f'{gate}({angle:{".2f" if isinstance(angle, (float, Float)) else ""}})'
return f'{gate}({angle:{".2f" if isinstance(angle, (float | Float)) else ""}})'


def _multi_angled_ascii_characters(
Expand All @@ -409,7 +409,7 @@ def format_string(angle: FreeParameterExpression | float) -> str:
Returns:
str: The ASCII representation of the angle.
"""
return ".2f" if isinstance(angle, (float, Float)) else ""
return ".2f" if isinstance(angle, (float | Float)) else ""

return f"{gate}({', '.join(f'{angle:{format_string(angle)}}' for angle in angles)})"

Expand Down
5 changes: 2 additions & 3 deletions src/braket/circuits/basis_state.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import annotations

from functools import singledispatch
from typing import Optional, Union

import numpy as np


class BasisState:
def __init__(self, state: BasisStateInput, size: Optional[int] = None): # noqa: UP007
def __init__(self, state: BasisStateInput, size: int | None = None):
self.state = _as_tuple(state, size)

@property
Expand Down Expand Up @@ -48,7 +47,7 @@ def __getitem__(self, item: int):
return BasisState(self.state[item])


BasisStateInput = Union[int, list[int], str, BasisState]
BasisStateInput = int | list[int] | str | BasisState


@singledispatch
Expand Down
9 changes: 3 additions & 6 deletions src/braket/circuits/braket_program_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# language governing permissions and limitations under the License.

from collections.abc import Iterable
from typing import Optional, Union

import numpy as np
from sympy import Expr, Number
Expand All @@ -32,7 +31,7 @@


class BraketProgramContext(AbstractProgramContext):
def __init__(self, circuit: Optional[Circuit] = None):
def __init__(self, circuit: Circuit | None = None):
"""Inits a `BraketProgramContext`.

Args:
Expand Down Expand Up @@ -143,9 +142,7 @@ def add_result(self, result: Results) -> None:
"""
self._circuit.add_result_type(braket_result_to_result_type(result))

def handle_parameter_value(
self, value: Union[float, Expr]
) -> Union[float, FreeParameterExpression]:
def handle_parameter_value(self, value: float | Expr) -> float | FreeParameterExpression:
"""Convert parameter value to required format.

Args:
Expand All @@ -163,7 +160,7 @@ def handle_parameter_value(
return value

def add_measure(
self, target: tuple[int], classical_targets: Optional[Iterable[int]] = None
self, target: tuple[int], classical_targets: Iterable[int] | None = None
) -> None:
"""Add a measure instruction to the circuit

Expand Down
8 changes: 4 additions & 4 deletions src/braket/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def add_circuit(
if target is not None:
keys = sorted(circuit.qubits)
values = target
target_mapping = dict(zip(keys, values))
target_mapping = dict(zip(keys, values, strict=False))

for instruction in circuit.instructions:
self.add_instruction(instruction, target_mapping=target_mapping)
Expand Down Expand Up @@ -678,7 +678,7 @@ def add_verbatim_box(
if target is not None:
keys = sorted(verbatim_circuit.qubits)
values = target
target_mapping = dict(zip(keys, values))
target_mapping = dict(zip(keys, values, strict=False))

if verbatim_circuit.result_types:
raise ValueError("Verbatim subcircuit is not measured and cannot have result types")
Expand Down Expand Up @@ -1403,7 +1403,7 @@ def _generate_frame_wf_defcal_declarations(
# Corresponding defcals with fixed arguments have been added
# in _get_frames_waveforms_from_instrs
if isinstance(gate, Parameterizable) and any(
not isinstance(parameter, (float, int, complex))
not isinstance(parameter, (float | int | complex))
for parameter in gate.parameters
):
continue
Expand Down Expand Up @@ -1511,7 +1511,7 @@ def _add_fixed_argument_calibrations(
)
additional_calibrations[bound_key] = calibration(**{
p.name if isinstance(p, FreeParameterExpression) else p: v
for p, v in zip(gate.parameters, instruction.operator.parameters)
for p, v in zip(gate.parameters, instruction.operator.parameters, strict=False)
})
return additional_calibrations

Expand Down
2 changes: 1 addition & 1 deletion src/braket/circuits/circuit_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def validate_circuit_and_shots(circuit: Circuit, shots: int) -> None:
if not circuit.observables_simultaneously_measurable:
raise ValueError("Observables cannot be sampled simultaneously")
for rt in circuit.result_types:
if isinstance(rt, (ResultType.Amplitude, ResultType.StateVector)):
if isinstance(rt, (ResultType.Amplitude | ResultType.StateVector)):
raise ValueError("StateVector or Amplitude cannot be specified when shots>0") # noqa: TRY004
if isinstance(rt, ResultType.Probability):
num_qubits = len(rt.target) or circuit.qubit_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# language governing permissions and limitations under the License.

from abc import abstractmethod
from typing import Optional, Union

from braket.circuits.instruction import Instruction
from braket.circuits.noise_model.criteria import Criteria
Expand All @@ -39,7 +38,7 @@ def instruction_matches(self, instruction: Instruction) -> bool:

@staticmethod
def _check_target_in_qubits(
qubits: Optional[set[Union[int, tuple[int]]]], target: QubitSetInput
qubits: set[int | tuple[int]] | None, target: QubitSetInput
) -> bool:
"""Returns true if the given targets of an instruction match the given qubit input set.

Expand Down
9 changes: 4 additions & 5 deletions src/braket/circuits/noise_model/criteria_input_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
# language governing permissions and limitations under the License.

from collections.abc import Iterable
from typing import Optional, Union

from braket.circuits.quantum_operator import QuantumOperator
from braket.registers.qubit_set import QubitSetInput


def parse_operator_input(
operators: Union[QuantumOperator, Iterable[QuantumOperator]],
) -> Optional[set[QuantumOperator]]:
operators: QuantumOperator | Iterable[QuantumOperator],
) -> set[QuantumOperator] | None:
"""Processes the quantum operator input to __init__ to validate and return a set of
QuantumOperators.

Expand All @@ -46,8 +45,8 @@ def parse_operator_input(


def parse_qubit_input(
qubits: Optional[QubitSetInput], expected_qubit_count: Optional[int] = 0
) -> Optional[set[Union[int, tuple[int]]]]:
qubits: QubitSetInput | None, expected_qubit_count: int | None = 0
) -> set[int | tuple[int]] | None:
"""Processes the qubit input to __init__ to validate and return a set of qubit targets.

Args:
Expand Down
8 changes: 4 additions & 4 deletions src/braket/circuits/noise_model/gate_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# language governing permissions and limitations under the License.

from collections.abc import Iterable
from typing import Any, Optional, Union
from typing import Any

from braket.circuits.gate import Gate
from braket.circuits.instruction import Instruction
Expand All @@ -30,8 +30,8 @@ class GateCriteria(CircuitInstructionCriteria):

def __init__(
self,
gates: Optional[Union[Gate, Iterable[Gate]]] = None,
qubits: Optional[QubitSetInput] = None,
gates: Gate | Iterable[Gate] | None = None,
qubits: QubitSetInput | None = None,
):
"""Creates Gate-based Criteria. See instruction_matches() for more details.

Expand Down Expand Up @@ -66,7 +66,7 @@ def applicable_key_types(self) -> Iterable[CriteriaKey]:
"""
return [CriteriaKey.QUBIT, CriteriaKey.GATE]

def get_keys(self, key_type: CriteriaKey) -> Union[CriteriaKeyResult, set[Any]]:
def get_keys(self, key_type: CriteriaKey) -> CriteriaKeyResult | set[Any]:
"""Gets the keys for a given CriteriaKey.

Args:
Expand Down
Loading