Pre-Report Checklist
Issue Description
The Program class was made hashable in a previous release:
|
def __hash__(self) -> int: |
However, the hash is based on the textual output (.out() method) and this is mutable because the list of instructions, calibrations etc are all mutable and contribute to the value. An instance of Program could be used as a dictionary key but the value could also change, making the dictionary behavior undefined.
See also:
|
def __hash__(self) -> int: |
Suggested Fix
There is no non-breaking fix for this issue. The least-jarring fix is to remove the method and to provide a FrozenProgram or equivalent which, in the case that the user was careful to avoid mutation in their workflow, would provide a new class to be used in place of Program with the same hash support. The preferred implementation would likely leverage solutions to:
rigetti/quil-rs#251
and
rigetti/quil-rs#252
Pre-Report Checklist
Issue Description
The
Programclass was made hashable in a previous release:pyquil/pyquil/quil.py
Line 969 in 6573ed0
However, the hash is based on the textual output (
.out()method) and this is mutable because the list of instructions, calibrations etc are all mutable and contribute to the value. An instance ofProgramcould be used as a dictionary key but the value could also change, making the dictionary behavior undefined.See also:
pyquil/pyquil/quil.py
Line 969 in 6573ed0
Suggested Fix
There is no non-breaking fix for this issue. The least-jarring fix is to remove the method and to provide a
FrozenProgramor equivalent which, in the case that the user was careful to avoid mutation in their workflow, would provide a new class to be used in place ofProgramwith the same hash support. The preferred implementation would likely leverage solutions to:rigetti/quil-rs#251
and
rigetti/quil-rs#252