Skip to content

BUG: measure_all adds extra register in ghz test #2

@MattePalte

Description

@MattePalte

Environment

  • qiskit.version: 0.22.0
  • Python version: 3.8.0
  • Operating system: Ubuntu 18.04

What is happening?

The measure_all in the file ghz.py of the test suite adds (perhaps involuntarily) another classical register instead of using the existing one. This makes the output double as big as it should be, with an empty register.

How can we reproduce the issue?

Run the following section of the circuit:

from qiskit import QuantumCircuit
from qiskit import execute, Aer

n_qubits = 10

def cx_chain(qc,n):
    for i in range(0,n-1):
        qc.cx(i,i+1)

qc = QuantumCircuit(n_qubits, n_qubits)
qc.h(0)
cx_chain(qc,n_qubits)
qc.measure_all()

simulator = Aer.get_backend('statevector_simulator')
job1 = execute(qc,simulator,shots=1000)
result1 = job1.result()
counts1 = result1.get_counts(qc)
print (counts1)

Output:

{'1111111111 0000000000': 498, '0000000000 0000000000': 502}

What should happen?

The existing register should be used instead of adding a new one.

Any suggestions?

Following the documentation of the measure_all method, it is possible to measure the qubits directly, without adding an extra register. The code should be changed to:

qc.measure_all(add_bits=False)

This produces the following:

{'1111111111': 531, '0000000000': 469}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions