question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

remove_final_measurements leaves clbit unusable

See original GitHub issue
c = QuantumCircuit(2, 5)
c.measure(0, 0)
c.measure(1, 1)
print(c)

     ┌─┐
q_0: ┤M├───
     └╥┘┌─┐
q_1: ─╫─┤M├
      ║ └╥┘
c: 5/═╩══╩═
      0  1

c.remove_final_measurements(inplace=True)
print(c)

q_0:

q_1:

c: 5/

c.measure(0, 0)     # raises error 

Note that as currently defined, remove_final_measurements() is supposed to remove the measurements plus the classical bits. But evidently it does not do that (looking at the two circuits above). Still, the clbit is unusable.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
kevinhartmancommented, Oct 26, 2021

I’m happy to address this while fixing the other issues discussed so far here.

I rewrote the final op determination logic to match the original doc string, while preserving @mtreinish’s bottom-up approach, and resolving a bug that existed in the implementation even before #7039.

Working on fixing other discussed issues with creg removal currently.

0reactions
kevinhartmancommented, Oct 21, 2021

While working on this, I noticed that the current behavior of the RemoveFinalMeasurements pass doesn’t match its doc string. Specifically,

Measurements and barriers are considered final if they are followed by no other operations (aside from other measurements or barriers.)

Currently, a measurement or barrier is only removed if it immediately precedes a qubit’s output node in the DAG. Only the final measurement or barrier will be removed in a chain of successive measure and barrier calls.

qr = QuantumRegister(1)
cr = ClassicalRegister(1)
c = QuantumCircuit(qr, cr)

c.measure(0, 0)
c.measure(0, 0)

dag = circuit_to_dag(c)
remove_final_meas = RemoveFinalMeasurements()
remove_final_meas.run(dag)

measure_node_count = [n.op.name for n in dag.op_nodes()].count("measure")

# error, measure_node_count is 1
self.assertEqual(measure_node_count, 0)

What’s the correct behavior here? Perhaps we should add a parameter to support either scenario. In that case, I wonder which should be the default?

I’m happy to address this while fixing the other issues discussed so far here.

@mtreinish @georgios-ts @kdk @ajavadia

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release Notes — Qiskit 0.37.0 documentation
Qiskit Metapackage Version qiskit‑terra qiskit‑aer qiskit‑ignis qiskit‑ibmq‑provider Release... 0.37.0 0.21.0 0.10.4 0.19.2 2022‑06... 0.36.2 0.20.2 0.10.4 0.7.1 0.19.1 2022‑05... 0.36.1 0.20.1 0.10.4 0.7.0 0.19.1 2022‑04...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found