Skip to content

Program should not be hashableΒ #1826

@mhodson-rigetti

Description

@mhodson-rigetti

Pre-Report Checklist

  • I am running the latest versions of pyQuil and the Forest SDK
  • I checked to make sure that this bug has not already been reported

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug πŸ›An issue that needs fixing.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions