diff --git a/pdm.lock b/pdm.lock index bf9bba516..bba10e0e3 100644 --- a/pdm.lock +++ b/pdm.lock @@ -42,7 +42,7 @@ files = [ [[package]] name = "amazon-braket-sdk" -version = "1.55.1.post0" +version = "1.56.0" requires_python = ">= 3.8.2" summary = "An open source library for interacting with quantum computing devices on Amazon Braket" dependencies = [ @@ -50,7 +50,7 @@ dependencies = [ "amazon-braket-schemas>=1.19.1", "backoff", "boltons", - "boto3>=1.22.3", + "boto3>=1.28.53", "nest-asyncio", "networkx", "numpy", @@ -61,8 +61,8 @@ dependencies = [ "sympy", ] files = [ - {file = "amazon-braket-sdk-1.55.1.post0.tar.gz", hash = "sha256:f7f32151d137ffb139c3fb17f568e49955bcb012fe2e04c2088227a46ebf69ff"}, - {file = "amazon_braket_sdk-1.55.1.post0-py3-none-any.whl", hash = "sha256:a987beb4ce61297ad4f60f3a79e027f01991ffa4b4e6c124be57b69884fd26a9"}, + {file = "amazon-braket-sdk-1.56.0.tar.gz", hash = "sha256:ca1dfa32e576db54f01ef068018c98241c1f39c9623e13aa334a807f31af48b4"}, + {file = "amazon_braket_sdk-1.56.0-py3-none-any.whl", hash = "sha256:2b213152222ebd888dcf18ae57ad63b222315abb9782b2894b56c26589ecb187"}, ] [[package]] @@ -322,22 +322,22 @@ files = [ [[package]] name = "boto3" -version = "1.28.45" +version = "1.28.55" requires_python = ">= 3.7" summary = "The AWS SDK for Python" dependencies = [ - "botocore<1.32.0,>=1.31.45", + "botocore<1.32.0,>=1.31.55", "jmespath<2.0.0,>=0.7.1", - "s3transfer<0.7.0,>=0.6.0", + "s3transfer<0.8.0,>=0.7.0", ] files = [ - {file = "boto3-1.28.45-py3-none-any.whl", hash = "sha256:682abbd304e93e726163d7de7448c1bf88108c72cf6a23dceb6bba86fdc86dff"}, - {file = "boto3-1.28.45.tar.gz", hash = "sha256:4ee914266c9bed16978677a367fd05053d8dcaddcbe998c9df30787ab73f87aa"}, + {file = "boto3-1.28.55-py3-none-any.whl", hash = "sha256:2680c0e36167e672777110ccef5303d59fa4a6a4f10086f9c14158c5cb008d5c"}, + {file = "boto3-1.28.55.tar.gz", hash = "sha256:2ceb644b1df7c3c8907913ab367a9900af79e271b4cfca37b542ec1fa142faf8"}, ] [[package]] name = "botocore" -version = "1.31.45" +version = "1.31.55" requires_python = ">= 3.7" summary = "Low-level, data-driven core of boto 3." dependencies = [ @@ -346,8 +346,8 @@ dependencies = [ "urllib3<1.27,>=1.25.4", ] files = [ - {file = "botocore-1.31.45-py3-none-any.whl", hash = "sha256:cceb150cff1d7f7a6faf655510a8384eb4505a33b430495fe1744d03a70dc66a"}, - {file = "botocore-1.31.45.tar.gz", hash = "sha256:85ff64a0ac2705c4ba36268c3b2dbc1184062e9cf729a89dd66c2f54f730fc79"}, + {file = "botocore-1.31.55-py3-none-any.whl", hash = "sha256:5ec27caa440257619712af0a71524cc2e56110fc502853c3e4046f87b65e42e9"}, + {file = "botocore-1.31.55.tar.gz", hash = "sha256:21ba89c4df083338ec463d9c2a8cffca42a99f9ad5f24bcac1870393b216c5a7"}, ] [[package]] @@ -2937,15 +2937,15 @@ files = [ [[package]] name = "s3transfer" -version = "0.6.2" +version = "0.7.0" requires_python = ">= 3.7" summary = "An Amazon S3 Transfer Manager" dependencies = [ "botocore<2.0a.0,>=1.12.36", ] files = [ - {file = "s3transfer-0.6.2-py3-none-any.whl", hash = "sha256:b014be3a8a2aab98cfe1abc7229cc5a9a0cf05eb9c1f2b86b230fd8df3f78084"}, - {file = "s3transfer-0.6.2.tar.gz", hash = "sha256:cab66d3380cca3e70939ef2255d01cd8aece6a4907a9528740f668c4b0611861"}, + {file = "s3transfer-0.7.0-py3-none-any.whl", hash = "sha256:10d6923c6359175f264811ef4bf6161a3156ce8e350e705396a7557d6293c33a"}, + {file = "s3transfer-0.7.0.tar.gz", hash = "sha256:fd3889a66f5fe17299fe75b82eae6cf722554edca744ca5d5fe308b104883d2e"}, ] [[package]] diff --git a/src/bloqade/builder/pragmas.py b/src/bloqade/builder/pragmas.py index 4de9b872d..cf3139517 100644 --- a/src/bloqade/builder/pragmas.py +++ b/src/bloqade/builder/pragmas.py @@ -45,16 +45,16 @@ def assign(self, **assignments) -> "Assign": class BatchAssignable: def batch_assign( self, - batch_params: List[Dict[str, ParamType]] = [], + __batch_params: List[Dict[str, ParamType]] = [], **assignments: List[ParamType], ) -> Union["BatchAssign", "ListAssign"]: from bloqade.builder.assign import BatchAssign, ListAssign - if len(batch_params) > 0 and assignments: + if len(__batch_params) > 0 and assignments: raise ValueError("batch_params and assignments cannot be used together.") - if len(batch_params) > 0: - return ListAssign(batch_params, parent=self) + if len(__batch_params) > 0: + return ListAssign(__batch_params, parent=self) else: return BatchAssign(assignments, parent=self) diff --git a/src/bloqade/ir/scalar.py b/src/bloqade/ir/scalar.py index 784c9ccb7..f2ce3c2e7 100644 --- a/src/bloqade/ir/scalar.py +++ b/src/bloqade/ir/scalar.py @@ -404,9 +404,14 @@ def _repr_pretty_(self, p, cycle): Printer(p).print(self, cycle) @validator("name", allow_reuse=True) - def validate_name(cls, v): - check_variable_name(v) - return v + def validate_name(cls, name): + check_variable_name(name) + if name in ["__batch_params"]: + raise ValidationError( + "Cannot use reserved name `__batch_params` for variable name" + ) + + return name @dataclass(frozen=True, repr=False) @@ -430,9 +435,14 @@ def print_node(self): return f"AssignedVariable: {self.name} = {self.value}" @validator("name", allow_reuse=True) - def validate_name(cls, v): - check_variable_name(v) - return v + def validate_name(cls, name): + check_variable_name(name) + if name in ["__batch_params"]: + raise ValidationError( + "Cannot use reserved name `__batch_params` for variable name" + ) + + return name @dataclass(frozen=True, repr=False) diff --git a/tests/test_builder.py b/tests/test_builder.py index 66d51b827..a402e5bc2 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -317,10 +317,50 @@ def test_assign_error(): ) list_dict = [dict(c=1, t=10), dict(c=2, t=20), dict(c=np, t=30)] - with pytest.raises(TypeError): start.rydberg.detuning.uniform.constant("c", "t").batch_assign(list_dict) + list_dict = [dict(c=1, t=10), dict(c=2, t=20), dict(t=30)] + with pytest.raises(ValueError): + start.rydberg.detuning.uniform.constant("c", "t").batch_assign(list_dict) + + list_dict = [dict(c=1, t=10, f=1), dict(c=2, t=20, f=2), dict(t=30, c=3, f=3)] + with pytest.raises(ValueError): + start.rydberg.detuning.uniform.constant("c", "t").batch_assign(list_dict) + + dict_list = dict( + c=[1, 2, 3], t=[10, 20, 30], mask=[[1, 2, 3], [4, 5, 6], [7, 8, 9]] + ) + + with pytest.raises(ValueError): + start.rydberg.detuning.uniform.constant("c", "t").batch_assign(**dict_list) + + list_dict = [ + dict(c=1, t=10, mask=[1, 2, 3]), + dict(c=2, t=20, mask=[4, 5, 6]), + dict(t=30, c=3, mask=[7, 8, 9]), + ] + + with pytest.raises(ValueError): + start.add_position([(0, 0), (0, 6)]).rydberg.detuning.var("mask").constant( + "c", "t" + ).batch_assign(list_dict) + + # happy path is to have a list of dicts with the same keys + start.add_position([(0, 0), (0, 6), (0, 12)]).rydberg.detuning.var("mask").constant( + "c", "t" + ).batch_assign(list_dict) + + list_dict = [ + dict(c=1, t=10, mask=np.array([1, 2, 3])), + dict(c=2, t=20, mask=np.array([4, 5, 6])), + dict(t=30, c=3, mask=np.array([7, 8, 9])), + ] + with pytest.raises(ValueError): + start.add_position([(0, 0), (0, 6)]).rydberg.detuning.var("mask").constant( + "c", "t" + ).batch_assign(list_dict) + with pytest.raises(TypeError): ( start.add_position((0, 0)) diff --git a/tests/test_scalar.py b/tests/test_scalar.py index dd434ae19..30bed1bf0 100644 --- a/tests/test_scalar.py +++ b/tests/test_scalar.py @@ -1,3 +1,4 @@ +from pydantic import ValidationError from bloqade import cast, var import bloqade.ir.scalar as scalar import pytest @@ -19,6 +20,9 @@ def test_var(): with pytest.raises(ValueError): var("a*b") + with pytest.raises(ValidationError): + var("__batch_params") + Vv = var("a") vs = var(Vv)