Skip to content

Commit

Permalink
fix: Fix circular dependency and error message/test strings resulting…
Browse files Browse the repository at this point in the history
… from style enforcement changes
  • Loading branch information
ltnln committed Jul 22, 2024
1 parent 079f1b4 commit 746ab2c
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 127 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from braket.analog_hamiltonian_simulator.rydberg.validators.device_validators.device_atom_arrangement import ( # noqa: E501 F401
DeviceAtomArrangementValidator,
)
from braket.analog_hamiltonian_simulator.rydberg.validators.device_validators.device_capabilities_constants import ( # noqa: E501 F401
DeviceCapabilitiesConstants,
)
from braket.analog_hamiltonian_simulator.rydberg.validators.device_validators.device_driving_field import ( # noqa: E501 F401
DeviceDrivingFieldValidator,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from braket.analog_hamiltonian_simulator.rydberg.validators.atom_arrangement import (
AtomArrangementValidator,
)
from braket.analog_hamiltonian_simulator.rydberg.validators.device_validators import (
from braket.analog_hamiltonian_simulator.rydberg.validators.device_capabilities_constants import (
DeviceCapabilitiesConstants,
)

Expand Down Expand Up @@ -37,8 +37,8 @@ def sites_defined_with_right_precision(cls, values):
[Decimal(str(coordinate)) % capabilities.SITE_PRECISION == 0 for coordinate in s]
):
raise ValueError(
f"Coordinates {idx}({s}) is defined with too high precision;\
they must be multiples of {capabilities.SITE_PRECISION} meters"
f"Coordinates {idx}({s}) is defined with too high precision;"
f"they must be multiples of {capabilities.SITE_PRECISION} meters"
)
return values

Expand All @@ -50,8 +50,8 @@ def sites_not_too_many(cls, values):
num_sites = len(sites)
if num_sites > capabilities.MAX_SITES:
raise ValueError(
f"There are too many sites ({num_sites}); there must be at most\
{capabilities.MAX_SITES} sites"
f"There are too many sites ({num_sites}); there must be at most "
f"{capabilities.MAX_SITES} sites"
)
return values

Expand All @@ -71,8 +71,8 @@ def sites_in_rows(cls, values):
continue
if row_distance < min_allowed_distance:
raise ValueError(
f"Sites {s1} and site {s2} have y-separation ({row_distance}). It must\
either be exactly zero or not smaller than {min_allowed_distance} meters"
f"Sites {s1} and site {s2} have y-separation ({row_distance}). It must "
f"either be exactly zero or not smaller than {min_allowed_distance} meters"
)
return values

Expand All @@ -84,7 +84,7 @@ def atom_number_limit(cls, values):
qubits = sum(filling)
if qubits > capabilities.MAX_FILLED_SITES:
raise ValueError(
f"Filling has {qubits} '1' entries; is must have not\
more than {capabilities.MAX_FILLED_SITES}"
f"Filling has {qubits} '1' entries; it must have not "
f"more than {capabilities.MAX_FILLED_SITES}"
)
return values
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic.v1.class_validators import root_validator

from braket.analog_hamiltonian_simulator.rydberg.validators.device_validators import (
from braket.analog_hamiltonian_simulator.rydberg.validators.device_capabilities_constants import (
DeviceCapabilitiesConstants,
)
from braket.analog_hamiltonian_simulator.rydberg.validators.driving_field import (
Expand Down Expand Up @@ -29,8 +29,8 @@ def amplitude_start_and_end_values(cls, values):
start_value, end_value = time_series_values[0], time_series_values[-1]
if start_value != 0 or end_value != 0:
raise ValueError(
f"The values of the Rabi frequency at the first and last time points are \
{start_value}, {end_value}; they both must be both 0."
f"The values of the Rabi frequency at the first and last time points are "
f"{start_value}, {end_value}; they both must be nonzero."
)
return values

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ class DeviceHamiltonianValidator(HamiltonianValidator):
def max_zero_local_detuning(cls, values):
LOCAL_RYDBERG_CAPABILITIES = values["LOCAL_RYDBERG_CAPABILITIES"]
local_detuning = values.get("localDetuning", [])
if not LOCAL_RYDBERG_CAPABILITIES:
if len(local_detuning) > 0:
raise ValueError(
f"Local detuning cannot be specified; \
if not LOCAL_RYDBERG_CAPABILITIES and len(local_detuning):
raise ValueError(
f"Local detuning cannot be specified; \
{len(local_detuning)} are given. Specifying local \
detuning is an experimental capability, use Braket Direct to request access."
)
)
return values
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

from braket.ir.ahs.program_v1 import Program

from braket.analog_hamiltonian_simulator.rydberg.validators.device_capabilities_constants import (
DeviceCapabilitiesConstants,
)
from braket.analog_hamiltonian_simulator.rydberg.validators.device_validators import (
DeviceAtomArrangementValidator,
DeviceCapabilitiesConstants,
DeviceDrivingFieldValidator,
DeviceHamiltonianValidator,
DeviceLocalDetuningValidator,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic.v1.class_validators import root_validator

from braket.analog_hamiltonian_simulator.rydberg.validators.device_validators import (
from braket.analog_hamiltonian_simulator.rydberg.validators.device_capabilities_constants import (
DeviceCapabilitiesConstants,
)
from braket.analog_hamiltonian_simulator.rydberg.validators.field_validator_util import (
Expand All @@ -22,8 +22,8 @@ def check_local_rydberg_capabilities(cls, values):
capabilities = values["capabilities"]
if not capabilities.LOCAL_RYDBERG_CAPABILITIES:
raise ValueError(
"Local Rydberg capabilities information has not been \
provided for local detuning."
"Local Rydberg capabilities information has not been "
"provided for local detuning."
)
return values

Expand All @@ -37,8 +37,8 @@ def magnitude_pattern_have_not_too_many_nonzeros(cls, values):
num_nonzeros = sum([p != 0.0 for p in pattern])
if num_nonzeros > capabilities.LOCAL_MAX_NONZERO_PATTERN_VALUES:
raise ValueError(
f"Number of nonzero magnitude pattern values is {num_nonzeros};\
it must not be more than {capabilities.LOCAL_MAX_NONZERO_PATTERN_VALUES}"
f"Number of nonzero magnitude pattern values is {num_nonzeros}; "
f"it must not be more than {capabilities.LOCAL_MAX_NONZERO_PATTERN_VALUES}"
)
return values

Expand Down Expand Up @@ -90,8 +90,8 @@ def local_detuning_start_and_end_values(cls, values):
start_value, end_value = time_series_values[0], time_series_values[-1]
if start_value != 0 or end_value != 0:
raise ValueError(
f"The values of the shifting field magnitude time series at the first\
and last time points are {start_value}, {end_value};\
they both must be both 0."
f"The values of the shifting field magnitude time series at the first "
f"and last time points are {start_value}, {end_value}; "
f"they both must be nonzero."
)
return values
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def validate_time_separation(times: List[Decimal], min_time_separation: Decimal,
time_diff = times[i + 1] - times[i]
if time_diff < min_time_separation:
raise ValueError(
f"Time points of {name} time_series, {i} ({times[i]}) and\
{i + 1} ({times[i + 1]}), are too close; they are separated\
by {time_diff} seconds. It must be at least {min_time_separation} seconds"
f"Time points of {name} time_series, {i} ({times[i]}) and "
f"{i + 1} ({times[i + 1]}), are too close; they are separated "
f"by {time_diff} seconds. It must be at least {min_time_separation} seconds"
)


Expand All @@ -123,8 +123,8 @@ def validate_value_precision(values: List[Decimal], max_precision: Decimal, name
for idx, v in enumerate(values):
if v % max_precision != 0:
raise ValueError(
f"Value {idx} ({v}) in {name} time_series is defined with too many digits;\
it must be an integer multiple of {max_precision}"
f"Value {idx} ({v}) in {name} time_series is defined with too many digits; "
f"it must be an integer multiple of {max_precision}"
)


Expand All @@ -137,17 +137,17 @@ def validate_max_absolute_slope(
slope = (values[idx + 1] - values[idx]) / (times[idx + 1] - times[idx])
if abs(slope) > max_slope:
raise ValueError(
f"For the {name} field, rate of change of values\
(between the {idx}-th and the {idx + 1}-th times)\
is {abs(slope)}, more than {max_slope}"
f"For the {name} field, rate of change of values "
f"(between the {idx}-th and the {idx + 1}-th times) "
f"is {abs(slope)}, more than {max_slope}"
)


def validate_time_precision(times: List[Decimal], time_precision: Decimal, name: str):
for idx, t in enumerate(times):
if t % time_precision != 0:
raise ValueError(
f"time point {idx} ({t}) of {name} time_series is\
defined with too many digits; it must be an\
integer multiple of {time_precision}"
f"time point {idx} ({t}) of {name} time_series is "
f"defined with too many digits; it must be an "
f"integer multiple of {time_precision}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from braket.analog_hamiltonian_simulator.rydberg.validators.device_validators import (
from braket.analog_hamiltonian_simulator.rydberg.validators.device_capabilities_constants import (
DeviceCapabilitiesConstants,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ def test_valid_atom_array(atom_arrangement_data, capabilities_with_local_rydberg
(
[[1.1e-6, 1.1e-6], [2.2e-6, 7.31e-6]],
[1, 0],
"Coordinates 1([2.2e-06, 7.31e-06]) is defined with too high precision;\
they must be multiples of 1E-7 meters",
"Coordinates 1([2.2e-06, 7.31e-06]) is defined with too high precision;"
"they must be multiples of 1E-7 meters",
),
(
[[3.201e-6, 0.0], [0.00, 4.1e-6], [-1.101e-6, 8.11e-6]],
[1, 0, 1],
"Coordinates 0([3.201e-06, 0.0]) is defined with too high precision;\
they must be multiples of 1E-7 meters",
"Coordinates 0([3.201e-06, 0.0]) is defined with too high precision;"
"they must be multiples of 1E-7 meters",
),
],
)
Expand Down Expand Up @@ -123,16 +123,16 @@ def test_atom_arrangement_sites_not_too_many(
(
[[Decimal("0.0"), Decimal("0.0")], [Decimal("5e-6"), Decimal("2.4e-6")]],
[0, 1],
"Sites [Decimal('0.0'), Decimal('0.0')] and site [Decimal('0.000005'),\
Decimal('0.0000024')] have y-separation (0.0000024). It must either be\
exactly zero or not smaller than 0.000004 meters",
"Sites [Decimal('0.0'), Decimal('0.0')] and site [Decimal('0.000005'), "
"Decimal('0.0000024')] have y-separation (0.0000024). It must either be "
"exactly zero or not smaller than 0.000004 meters",
),
(
[[Decimal("0.0"), Decimal("0.0")], [Decimal("5e-6"), Decimal("1.4e-6")]],
[0, 1],
"Sites [Decimal('0.0'), Decimal('0.0')] and site [Decimal('0.000005'),\
Decimal('0.0000014')] have y-separation (0.0000014). It must either\
be exactly zero or not smaller than 0.000004 meters",
"Sites [Decimal('0.0'), Decimal('0.0')] and site [Decimal('0.000005'), "
"Decimal('0.0000014')] have y-separation (0.0000014). It must either "
"be exactly zero or not smaller than 0.000004 meters",
),
],
)
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_atom_arrangement_filling_atom_number_limit(
[0.00005, 0.00004],
[0.00005, 0],
]
error_message = "Filling has 5 '1' entries; is must have not more than 4"
error_message = "Filling has 5 '1' entries; it must have not more than 4"
_assert_atom_arrangement(
mock_atom_arrangement_data, error_message, non_local_capabilities_constants
)
Loading

0 comments on commit 746ab2c

Please sign in to comment.