Skip to content

Commit

Permalink
feat: Test Device IR validator and support None max_net_detuning in P…
Browse files Browse the repository at this point in the history
…rogram Validator
  • Loading branch information
ltnln committed Jul 23, 2024
1 parent b6da508 commit 8620b84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# language governing permissions and limitations under the License.

from copy import deepcopy
from typing import Union

from braket.ir.ahs.program_v1 import Program
from pydantic.v1 import root_validator
Expand All @@ -20,13 +21,16 @@
from braket.analog_hamiltonian_simulator.rydberg.validators.capabilities_constants import (
CapabilitiesConstants,
)
from braket.analog_hamiltonian_simulator.rydberg.validators.device_capabilities_constants import (
DeviceCapabilitiesConstants,
)
from braket.analog_hamiltonian_simulator.rydberg.validators.field_validator_util import (
validate_net_detuning_with_warning,
)


class ProgramValidator(Program):
capabilities: CapabilitiesConstants
capabilities: Union[CapabilitiesConstants, DeviceCapabilitiesConstants]

# The pattern of the shifting field must have the same length as the lattice_sites
@root_validator(pre=True, skip_on_failure=True)
Expand Down Expand Up @@ -61,7 +65,7 @@ def net_detuning_must_not_exceed_max_net_detuning(cls, values):
# If no local detuning, we simply return the values
# because there are separate validators to validate
# the global driving fields in the program
if not len(local_detuning):
if not len(local_detuning) or not capabilities.MAX_NET_DETUNING:
return values

detuning_times = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
from pydantic.v1.error_wrappers import ValidationError

from braket.analog_hamiltonian_simulator.rydberg.validators.device_ir_validator import (
validate_program,
)


def test_validate_program(program_data, capabilities_with_local_rydberg):
try:
validate_program(program=program_data, device_capabilities=capabilities_with_local_rydberg)
except ValidationError as e:
pytest.fail(f"Validate program is failing : {str(e)}")

0 comments on commit 8620b84

Please sign in to comment.