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

1611 Regression fix for Program.copy_everything_except_instructions() #1612

Merged
Merged
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
3 changes: 1 addition & 2 deletions pyquil/api/_rewrite_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ 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)))
# Program.copy_everything_except_instructions persists DECLARE statements
elif not isinstance(inst, Declare):
else:
updated.inst(inst)

if mref_idx > 0:
Expand Down
6 changes: 2 additions & 4 deletions pyquil/quil.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ 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()
new_prog._frames = self.frames.copy()
Expand All @@ -203,8 +200,9 @@ def copy(self) -> "Program":
:return: a new Program
"""
new_prog = self.copy_everything_except_instructions()
new_prog = self.copy_everything_except_instructions() # and declarations, which is a view
new_prog._instructions = self._instructions.copy()
new_prog._declarations = self._declarations.copy()
return new_prog

@property
Expand Down
4 changes: 3 additions & 1 deletion test/unit/test_quantum_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ def test_qc_expectation_on_qvm(client_configuration: QCSClient, dummy_compiler:

def test_undeclared_memory_region(client_configuration: QCSClient, dummy_compiler: DummyCompiler):
"""
Fix for https://github.com/rigetti/pyquil/issues/1596
Test for https://github.com/rigetti/pyquil/issues/1596
"""
program = Program(
"""
Expand All @@ -847,6 +847,8 @@ def test_undeclared_memory_region(client_configuration: QCSClient, dummy_compile
"""
)
program = program.copy_everything_except_instructions()
assert len(program.instructions) == 0 # the purpose of copy_everything_except_instructions()
assert len(program.declarations) == 0 # this is a view on the instructions member; must be consistent
qc = QuantumComputer(name="testy!", qam=QVM(client_configuration=client_configuration), compiler=dummy_compiler)
executable = qc.compiler.native_quil_to_executable(program)
qc.run(executable)
Expand Down