Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary repeated measurement #1

Open
MattePalte opened this issue Mar 1, 2024 · 0 comments
Open

Unnecessary repeated measurement #1

MattePalte opened this issue Mar 1, 2024 · 0 comments

Comments

@MattePalte
Copy link

Environment

  • qiskit.version: 0.45.2
  • Python version: 3.10.12
  • Operating system: Ubuntu 20.04

What is happening?

In the Python file RSA_Breaker-4-bit.py there is a while loop that adds measurements to the circuit. However, every time that the loop runs, the measurements are added to the same qubits, and some qubits there are also never modifies in the loop, e.g. (qr[4], qr[5], qr[6], qr[7], qr[8], ..., qr[15]).
This leads to multiple measurement in series, with nothing in between, which is typically unnecessary.

How can we reproduce the issue?

Simply add print(circuit.draw()) at the end of each loop iteration to notice the series of measurements.

What should happen?

I would have expected to measure only once for the qubits that are not modified in the loop.

Any suggestions?

I would suggest measuring the fixed qubits before the loop, and then only measure the qubits that are modified in the loop.

    ...
    qc.measure(range(4, 16), range(4, 16))  # new
    while np.logical_or(x != x0, r <= 0):
        r+=1
        qc.measure(range(4), range(4)) # replaced
        for i in range(0,3): 
            qc.x(qr[i])
        qc.cx(qr[2],qr[1])
        qc.cx(qr[1],qr[2])
        qc.cx(qr[2],qr[1])
        qc.cx(qr[1],qr[0])
        qc.cx(qr[0],qr[1])
        qc.cx(qr[1],qr[0])
        qc.cx(qr[3],qr[0])
        qc.cx(qr[0],qr[1])
        qc.cx(qr[1],qr[0])
        
        result = execute(qc,backend = qasm_sim, shots=1024).result()
        counts = result.get_counts()
        
        results = [[],[]]
        for key,value in counts.items(): 
            results[0].append(key)
            results[1].append(int(value))
        s = results[0][np.argmax(np.array(results[1]))]
    ...

Thanks in advance, I wish you a happy and productive day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant