Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
4.91k stars 2.31k forks source link

Calling `synth(registerless=False)` on a classical function synth labels the qubits wrongly #9363

Closed 1ucian0 closed 11 months ago

1ucian0 commented 1 year ago

Environment

What is happening?

In https://github.com/Qiskit/qiskit-terra/pull/9337#discussion_r1067055542 @Cryoris noticed that classical_function synthesis labels the qubits in the reversed order.

How can we reproduce the issue?

:

from qiskit.circuit.classicalfunction import classical_function
from qiskit.circuit.classicalfunction.types import Int1

@classical_function
def grover_oracle(a: Int1, b: Int1, c: Int1) -> Int1:
    return (a and b and not c)

quantum_circuit = grover_oracle.synth(registerless=False)
print(quantum_circuit.draw())
     c: ──■──
          │  
     b: ──■──
          │  
     a: ──o──
        ┌─┴─┐
return: ┤ X ├
        └───┘

What should happen?

in that example, the open control is on c, not on a.

Any suggestions?

No response

1ucian0 commented 1 year ago

I'm not sure here what's expected. It could be either:

     a: ──■──
          │  
     b: ──■──
          │  
     c: ──o──
        ┌─┴─┐
return: ┤ X ├
        └───┘

or

     c: ──o──
          │  
     b: ──■──
          │  
     a: ──■──
        ┌─┴─┐
return: ┤ X ├
        └───┘

Tweedledum seems to prefer the first option.

Cryoris commented 1 year ago

What do we expect the function signature to look like: def oracle(q_0, q_1, q_2) or def oracle(q_2, q_1, q_0)? It seems the "Qiskit way" would be q_2, q_1, q_0 so the top labelling in your example would seem correct to me 🙂

jakelishman commented 1 year ago

You could argue either way - def oracle(q_0, q_1, q_2) satisfies *args where args[0] == q_0 and so on, so the indexing matches the actual usage, whereas def oracle(q_2, q_1, q_0) just looks kind of like how bitstrings are printed. The former is probably better, because it matches the semantics when passing qargs in a list to things like QuantumCircuit.append.