Skip to content

Commit

Permalink
fix: copy_everything_but_instructions now correctly copies `DECLARE…
Browse files Browse the repository at this point in the history
…` statements (#1600)

* fix: `copy_everything_but_instructions` now correctly copies `DECLARE`
statements.

* fix rewrite_arithmetic

* simplify declaration iteration

Co-authored-by: Michael Bryant <[email protected]>

* add clarifying comment

---------

Co-authored-by: Michael Bryant <[email protected]>
  • Loading branch information
MarquessV and Shadow53 committed Jun 27, 2023
1 parent fe3c837 commit fa7fb71
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyquil/api/_rewrite_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def expr_mref(expr: object) -> MemoryReference:
# so we divide by 8...
expr = str(Div(inst.scale, 8))
updated.inst(SetScale(inst.frame, expr_mref(expr)))
else:
# Program.copy_everything_except_instructions persists DECLARE statements
elif not isinstance(inst, Declare):
updated.inst(inst)

if mref_idx > 0:
Expand Down
2 changes: 2 additions & 0 deletions pyquil/quil.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def copy_everything_except_instructions(self) -> "Program":
"""
new_prog = Program()
new_prog._calibrations = self.calibrations.copy()
for declaration in self.declarations.values():
new_prog.inst(declaration)
new_prog._declarations = self._declarations.copy()
new_prog._waveforms = self.waveforms.copy()
new_prog._defined_gates = self._defined_gates.copy()
Expand Down
20 changes: 20 additions & 0 deletions test/unit/test_quantum_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,26 @@ def test_qc_expectation_on_qvm(client_configuration: QCSClient, dummy_compiler:
assert results[2][0].total_counts == 20000


def test_undeclared_memory_region(client_configuration: QCSClient, dummy_compiler: DummyCompiler):
"""
Fix for https://github.com/rigetti/pyquil/issues/1596
"""
program = Program(
"""
DECLARE beta REAL[1]
RZ(0.5) 0
CPHASE(pi) 0 1
DECLARE ro BIT[2]
MEASURE 0 ro[0]
MEASURE 1 ro[1]
"""
)
program = program.copy_everything_except_instructions()
qc = QuantumComputer(name="testy!", qam=QVM(client_configuration=client_configuration), compiler=dummy_compiler)
executable = qc.compiler.native_quil_to_executable(program)
qc.run(executable)


@pytest.mark.skip # qcs_sdk client profiles do not support group accounts
@respx.mock
def test_get_qc_with_group_account(client_configuration: QCSClient, qcs_aspen8_isa: InstructionSetArchitecture):
Expand Down

0 comments on commit fa7fb71

Please sign in to comment.