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

style: update linter to use UP rules #193

Merged
merged 1 commit into from
Mar 24, 2025
Merged
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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ line-length = 100
lint.isort = { known-first-party = [
"braket",
] }
lint.extend-select = ["I"]
lint.extend-select = ["I", "UP", "PERF"]
lint.preview = true

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

from typing import List

from pydantic.v1 import conlist, constr

Expand Down Expand Up @@ -42,5 +41,5 @@ class BlackbirdDeviceActionProperties(DeviceActionProperties):
"""

actionType: constr(regex=r"^braket\.ir\.blackbird\.program$")
supportedOperations: List[str]
supportedOperations: list[str]
supportedResultTypes: conlist(ResultType, max_items=0)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# 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

from pydantic.v1 import Field

Expand Down Expand Up @@ -63,11 +62,11 @@ class ContinuousVariableQpuParadigmProperties(BraketSchemaBase):
name="braket.device_schema.continuous_variable_qpu_paradigm_properties", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
modes: Dict[str, float]
modes: dict[str, float]
layout: str
compiler: List[str]
supportedLanguages: List[str]
compiler: list[str]
supportedLanguages: list[str]
compilerDefault: str
nativeGateSet: List[str]
gateParameters: Dict[str, List[List[float]]]
nativeGateSet: list[str]
gateParameters: dict[str, list[list[float]]]
target: str
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License

from typing import List, Optional, Union
from typing import Optional, Union

from pydantic.v1 import Field

Expand Down Expand Up @@ -80,15 +80,15 @@ class Dwave2000QDeviceLevelParameters(BraketSchemaBase):
name="braket.device_schema.dwave.dwave_2000Q_device_level_parameters", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
annealingOffsets: Optional[List[float]]
annealingSchedule: Optional[List[List[float]]]
annealingOffsets: Optional[list[float]]
annealingSchedule: Optional[list[list[float]]]
annealingDuration: Optional[float] = Field(gt=0)
autoScale: Optional[bool]
beta: Optional[float]
chains: Optional[List[List[int]]]
chains: Optional[list[list[int]]]
compensateFluxDrift: Optional[bool]
fluxBiases: Optional[List[float]]
initialState: Optional[List[int]]
fluxBiases: Optional[list[float]]
initialState: Optional[list[int]]
maxResults: Optional[int] = Field(gt=0)
postprocessingType: Optional[Union[PostProcessingType, str]]
programmingThermalizationDuration: Optional[int]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License

from typing import List, Optional
from typing import Optional

from pydantic.v1 import Field

Expand Down Expand Up @@ -69,13 +69,13 @@ class DwaveAdvantageDeviceLevelParameters(BraketSchemaBase):
name="braket.device_schema.dwave.dwave_advantage_device_level_parameters", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
annealingOffsets: Optional[List[float]]
annealingSchedule: Optional[List[List[float]]]
annealingOffsets: Optional[list[float]]
annealingSchedule: Optional[list[list[float]]]
annealingDuration: Optional[float] = Field(gt=0)
autoScale: Optional[bool]
compensateFluxDrift: Optional[bool]
fluxBiases: Optional[List[float]]
initialState: Optional[List[int]]
fluxBiases: Optional[list[float]]
initialState: Optional[list[int]]
maxResults: Optional[int] = Field(gt=0)
programmingThermalizationDuration: Optional[int]
readoutThermalizationDuration: Optional[int]
Expand Down
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 enum import Enum
from typing import List, Optional, Union
from typing import Optional, Union

from pydantic.v1 import Field

Expand Down Expand Up @@ -97,15 +97,15 @@ class DwaveProviderLevelParameters(BraketSchemaBase):
name="braket.device_schema.dwave.dwave_provider_level_parameters", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
annealingOffsets: Optional[List[float]]
annealingSchedule: Optional[List[List[float]]]
annealingOffsets: Optional[list[float]]
annealingSchedule: Optional[list[list[float]]]
annealingDuration: Optional[int] = Field(gt=0)
autoScale: Optional[bool]
beta: Optional[float]
chains: Optional[List[List[int]]]
chains: Optional[list[list[int]]]
compensateFluxDrift: Optional[bool]
fluxBiases: Optional[List[float]]
initialState: Optional[List[int]]
fluxBiases: Optional[list[float]]
initialState: Optional[list[int]]
maxResults: Optional[int] = Field(gt=0)
postprocessingType: Optional[Union[PostProcessingType, str]]
programmingThermalizationDuration: Optional[int]
Expand Down
25 changes: 12 additions & 13 deletions src/braket/device_schema/dwave/dwave_provider_properties_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

from typing import List

from pydantic.v1 import Field

Expand Down Expand Up @@ -67,23 +66,23 @@ class DwaveProviderProperties(BraketSchemaBase):
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
annealingOffsetStep: float
annealingOffsetStepPhi0: float
annealingOffsetRanges: List[List[float]]
annealingDurationRange: List[float]
couplers: List[List[int]]
annealingOffsetRanges: list[list[float]]
annealingDurationRange: list[float]
couplers: list[list[int]]
defaultAnnealingDuration: int
defaultProgrammingThermalizationDuration: int
defaultReadoutThermalizationDuration: int
extendedJRange: List[float]
hGainScheduleRange: List[float]
hRange: List[float]
jRange: List[float]
extendedJRange: list[float]
hGainScheduleRange: list[float]
hRange: list[float]
jRange: list[float]
maximumAnnealingSchedulePoints: int
maximumHGainSchedulePoints: int
perQubitCouplingRange: List[float]
programmingThermalizationDurationRange: List[int]
qubits: List[int]
perQubitCouplingRange: list[float]
programmingThermalizationDurationRange: list[int]
qubits: list[int]
qubitCount: int
quotaConversionRate: float
readoutThermalizationDurationRange: List[int]
taskRunDurationRange: List[int]
readoutThermalizationDurationRange: list[int]
taskRunDurationRange: list[int]
topology: dict
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import json
from importlib import import_module
from typing import Optional, Type
from typing import Optional

from pydantic.v1 import Field

Expand Down Expand Up @@ -97,7 +97,7 @@ class IonqProviderProperties(BraketSchemaBase):
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
fidelity: dict[str, dict[str, float]]
timing: dict[str, float]
errorMitigation: Optional[dict[Type[ErrorMitigationScheme], ErrorMitigationProperties]] = None
errorMitigation: Optional[dict[type[ErrorMitigationScheme], ErrorMitigationProperties]] = None

class Config:
json_loads = _loads_with_error_mitigation
Expand Down
6 changes: 3 additions & 3 deletions src/braket/device_schema/jaqcd_device_action_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

from typing import List, Optional
from typing import Optional

from pydantic.v1 import constr

Expand Down Expand Up @@ -49,6 +49,6 @@ class JaqcdDeviceActionProperties(DeviceActionProperties):
"""

actionType: constr(regex=r"^braket\.ir\.jaqcd\.program$")
supportedOperations: List[str]
supportedResultTypes: Optional[List[ResultType]]
supportedOperations: list[str]
supportedResultTypes: Optional[list[ResultType]]
disabledQubitRewiringSupported: Optional[bool] = None
4 changes: 2 additions & 2 deletions src/braket/device_schema/oqc/oqc_device_capabilities_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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 typing import Optional, Union

from pydantic.v1 import Field

Expand Down Expand Up @@ -114,7 +114,7 @@ class OqcDeviceCapabilities(BraketSchemaBase, DeviceCapabilities):
name="braket.device_schema.oqc.oqc_device_capabilities", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
action: Dict[
action: dict[
Union[DeviceActionType, str],
Union[OpenQASMDeviceActionProperties, JaqcdDeviceActionProperties],
]
Expand Down
12 changes: 6 additions & 6 deletions src/braket/device_schema/oqc/oqc_provider_properties_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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 typing import TypeVar, Union

from pydantic.v1 import Field

Expand All @@ -20,11 +20,11 @@
# TODO: Replace the calibration data with actual values we receive from the device.


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]]])
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]])
QubitType = TypeVar("QubitType", bound=dict[str, Union[OneQubitType, TwoQubitType]])


class OqcProviderProperties(BraketSchemaBase):
Expand Down Expand Up @@ -73,4 +73,4 @@ class OqcProviderProperties(BraketSchemaBase):
name="braket.device_schema.oqc.oqc_provider_properties", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
properties: Dict[str, Dict[str, QubitType]]
properties: dict[str, dict[str, QubitType]]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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 typing import Optional, Union

from pydantic.v1 import Field

Expand Down Expand Up @@ -98,7 +98,7 @@ class XanaduDeviceCapabilities(BraketSchemaBase, DeviceCapabilities):
name="braket.device_schema.xanadu.xanadu_device_capabilities", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
action: Dict[
action: dict[
Union[DeviceActionType, str],
Union[BlackbirdDeviceActionProperties],
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# 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

from pydantic.v1 import Field

Expand Down Expand Up @@ -59,9 +58,9 @@ class XanaduProviderProperties(BraketSchemaBase):
name="braket.device_schema.xanadu.xanadu_provider_properties", version="1"
)
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
loopPhases: List[float]
loopPhases: list[float]
schmidtNumber: float
commonEfficiency: float
squeezingParametersMean: Dict[str, float]
relativeChannelEfficiencies: List[float]
loopEfficiencies: List[float]
squeezingParametersMean: dict[str, float]
relativeChannelEfficiencies: list[float]
loopEfficiencies: list[float]
6 changes: 3 additions & 3 deletions src/braket/ir/annealing/problem_v1.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 enum import Enum
from typing import Dict, Union
from typing import Union

from pydantic.v1 import Field, conint

Expand Down Expand Up @@ -48,5 +48,5 @@ class Problem(BraketSchemaBase):
_PROBLEM_HEADER = BraketSchemaHeader(name="braket.ir.annealing.problem", version="1")
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROBLEM_HEADER, const=_PROBLEM_HEADER)
type: Union[ProblemType, str]
linear: Dict[conint(ge=0), float]
quadratic: Dict[str, float]
linear: dict[conint(ge=0), float]
quadratic: dict[str, float]
2 changes: 1 addition & 1 deletion src/braket/ir/gate_model_shared/shared_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def validate_probabilities(cls, values):
f"{i} is not allowed as a key. Please enter only non-identity Pauli strings."
)

for pauli_string, prob in probabilities.items():
for pauli_string in probabilities.keys():
if len(pauli_string) != qubit_count:
raise ValueError("Length of each Pauli string must be equal to number of qubits.")

Expand Down
8 changes: 4 additions & 4 deletions src/braket/ir/jaqcd/program_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

from typing import Any, List, Optional, Union
from typing import Any, Optional, Union

from pydantic.v1 import BaseModel, Field, validator

Expand Down Expand Up @@ -217,9 +217,9 @@ class Program(BraketSchemaBase):

_PROGRAM_HEADER = BraketSchemaHeader(name="braket.ir.jaqcd.program", version="1")
braketSchemaHeader: BraketSchemaHeader = Field(default=_PROGRAM_HEADER, const=_PROGRAM_HEADER)
instructions: List[Any]
results: Optional[List[Results]]
basis_rotation_instructions: Optional[List[Any]]
instructions: list[Any]
results: Optional[list[Results]]
basis_rotation_instructions: Optional[list[Any]]

@validator("instructions", "basis_rotation_instructions", each_item=True, pre=True)
def validate_instructions(cls, value, field):
Expand Down