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

Ensure scalar parameter names are preserved during conversion #6755

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions cirq-rigetti/cirq_rigetti/quil_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ def quil_expression_to_sympy(expression: ParameterDesignator):
elif isinstance(expression, Parameter): # pragma: no cover
return sympy.Symbol(expression.name)
elif isinstance(expression, MemoryReference):
if expression.declared_size == 1:
return sympy.Symbol(expression.name)
return sympy.Symbol(expression.name + f"_{expression.offset}")
elif isinstance(expression, Function):
if expression.name == "SIN": # pragma: no cover
Expand Down
13 changes: 13 additions & 0 deletions cirq-rigetti/cirq_rigetti/quil_input_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,19 @@ def test_parametric_quil():
assert cirq_circuit == circuit


QUIL_PROGRAM_WITH_SINGLE_PARAMETER = """
DECLARE theta REAL[1]
RZ(theta) 0
"""


def test_scalar_param_name_unchanged_by_conversion():
"""Ensure the name of scalar parameter does not change during conversion."""
program = Program(QUIL_PROGRAM_WITH_SINGLE_PARAMETER)
circuit = circuit_from_quil(program)
assert cirq.parameter_names(circuit) == {"theta"}


def test_measurement_without_classical_reg():
"""Measure operations must declare a classical register."""
with pytest.raises(UnsupportedQuilInstruction):
Expand Down
Loading