Skip to content

DAGCircuit with vars does not compare equal after pickling #14007

@kevinhartman

Description

@kevinhartman

Environment

  • Qiskit version: a00279bc7d6005bfc5ea783cd1fe336784160518
  • Python version: 3.11
  • Operating system: macOS Sonoma 14.4

What is happening?

After pickling, DAGCircuit is no longer equal to itself if it contains variables.

This issue predates all changes made in support of stretch (the above test fails on the commit prior to the first PR in that series).

How can we reproduce the issue?

def test_pickle_identifiers(self):
    """Test identifiers preserved through pickle."""
    a = expr.Var.new("a", types.Bool())
    b = expr.Var.new("b", types.Uint(8))

    # Check captures and declarations.
    dag = DAGCircuit()
    dag.add_declared_var(a)
    dag.add_captured_var(b)

    self.assertEqual(dag.num_vars, 2)
    self.assertEqual(dag.num_captured_vars, 1)
    self.assertEqual(dag.num_declared_vars, 1)

    with io.BytesIO() as buf:
        pickle.dump(dag, buf)
        buf.seek(0)
        output = pickle.load(buf)

    self.assertEqual(output.num_vars, 2)
    self.assertEqual(output.num_captured_vars, 1)
    self.assertEqual(output.num_declared_vars, 1)
    self.assertEqual(output, dag) # < --- FAILS

What should happen?

The circuits should be equal.

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions