Skip to content

Commit

Permalink
Rename build_if_necessary param
Browse files Browse the repository at this point in the history
  • Loading branch information
rmshaffer committed May 14, 2024
1 parent d3cb14e commit 7e4441d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package_dir={"": "src"},
install_requires=[
# Pin the latest commit of mcm-sim branch of amazon-braket/amazon-braket-sdk-python.git
"amazon-braket-sdk @ git+https://github.com/amazon-braket/amazon-braket-sdk-python.git@fe601096b7bba2a1bd8700896080d93672732c4c#egg=amazon-braket-sdk", # noqa E501
"amazon-braket-sdk @ git+https://github.com/amazon-braket/amazon-braket-sdk-python.git@da74ee713c200ac0803704bb0b4c87f9d0100682#egg=amazon-braket-sdk", # noqa E501
"amazon-braket-default-simulator>=1.23.2",
"oqpy~=0.3.5",
"diastatic-malt",
Expand Down
12 changes: 6 additions & 6 deletions src/autoqasm/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,28 @@ def build(self, device: Device | str | None = None) -> Program:
def to_ir(
self,
ir_type: IRType = IRType.OPENQASM,
allow_implicit_build: bool = False,
build_if_necessary: bool = False,
serialization_properties: SerializationProperties = OpenQASMSerializationProperties(),
) -> str:
"""Serializes the program into an intermediate representation.
Args:
ir_type (IRType): The IRType to use for converting the program to its
IR representation. Defaults to IRType.OPENQASM.
allow_implicit_build (bool): Whether to allow the program to be implicitly
build_if_necessary (bool): Whether to allow the program to be implicitly
built as a side effect of calling this function. Defaults to False.
serialization_properties (SerializationProperties): IR serialization configuration.
Default to OpenQASMSerializationProperties().
Raises:
ValueError: Raised if the supplied `ir_type` is not supported.
RuntimeError: Raised if `allow_implicit_build` is False, since a MainProgram object
RuntimeError: Raised if `build_if_necessary` is False, since a MainProgram object
has not yet been built.
Returns:
str: A representation of the program in the `ir_type` format.
"""
if not allow_implicit_build:
if not build_if_necessary:
raise RuntimeError(
"The AutoQASM program cannot be serialized because it has not yet been built. "
"To serialize the program, first call build() to obtain a built Program object, "
Expand Down Expand Up @@ -227,15 +227,15 @@ def make_bound_program(self, param_values: dict[str, float], strict: bool = Fals
def to_ir(
self,
ir_type: IRType = IRType.OPENQASM,
allow_implicit_build: bool = True,
build_if_necessary: bool = True,
serialization_properties: SerializationProperties = OpenQASMSerializationProperties(),
) -> str:
"""Serializes the program into an intermediate representation.
Args:
ir_type (IRType): The IRType to use for converting the program to its
IR representation. Defaults to IRType.OPENQASM.
allow_implicit_build (bool): Whether to allow the program to be implicitly
build_if_necessary (bool): Whether to allow the program to be implicitly
built as a side effect of calling this function. Defaults to True.
This parameter is ignored for the Program class, since the program has
already been built.
Expand Down
8 changes: 4 additions & 4 deletions test/unit_tests/autoqasm/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,11 +952,11 @@ def empty_program() -> None:
def test_to_ir_implicit_build(empty_program) -> None:
"""Test that to_ir works as expected with and without implicit build."""
expected = """OPENQASM 3.0;"""
assert empty_program.build().to_ir(allow_implicit_build=False) == expected
assert empty_program.build().to_ir(allow_implicit_build=True) == expected
assert empty_program.to_ir(allow_implicit_build=True) == expected
assert empty_program.build().to_ir(build_if_necessary=False) == expected
assert empty_program.build().to_ir(build_if_necessary=True) == expected
assert empty_program.to_ir(build_if_necessary=True) == expected
with pytest.raises(RuntimeError):
empty_program.to_ir(allow_implicit_build=False)
empty_program.to_ir(build_if_necessary=False)


def test_main_no_return():
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ commands =
[test-deps]
deps =
# If you need to test on a certain branch, add @<branch-name> after .git
git+https://github.com/amazon-braket/amazon-braket-sdk-python.git@fe601096b7bba2a1bd8700896080d93672732c4c # mcm-sim branch
git+https://github.com/amazon-braket/amazon-braket-sdk-python.git@da74ee713c200ac0803704bb0b4c87f9d0100682 # mcm-sim branch
git+https://github.com/amazon-braket/amazon-braket-default-simulator-python.git

0 comments on commit 7e4441d

Please sign in to comment.