pennylane icon indicating copy to clipboard operation
pennylane copied to clipboard

Add warning to assist with name degeneracy of `qml.X`/`qml.PauliX`.

Open glassnotes opened this issue 2 years ago • 5 comments

Feature details

Due to the similarity, it is easy to confuse qml.X and qml.PauliX, especially since other methods of specifying circuits, e.g., QASM, use x for PauliX. But if a user uses qml.X in their circuit on a qubit device, nothing happens to inform them that the incorrect operation is being used:

@qml.qnode(dev)
def circ():
    qml.PauliX(wires=0)
    qml.Hadamard(wires=1)
    qml.X(wires=1)
    return qml.probs(wires=1)
>>> print(qml.draw(circ)())
 0: ──X──┤       
 1: ──H──┤ Probs 

It would be nice to raise a warning in this case, and inform the user of the correct name of the gate (I guess since it is an observable, and not an operation, it doesn't get flagged as an unsupported operation like the CV operations).

Implementation

Most straightforward way might be to override the supports_operation method in the default.qubit device to add a custom check for qml.X, and then call the parent class method.

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

No response

glassnotes avatar Nov 25 '21 14:11 glassnotes

@glassnotes I wonder if this is intentional behaviour, because potentially in the future we could have support of a 'mixed' qubit-CV device 🤔

Out of curiosity, do you get an error if you add expansion_strategy="device" to the draw function?

josh146 avatar Nov 25 '21 14:11 josh146

@josh146 no error is raised, which I did not expect! It prints exactly the same circuit.

glassnotes avatar Nov 25 '21 14:11 glassnotes

Huh! I am also surprised

josh146 avatar Nov 25 '21 14:11 josh146

Hi! I'm interested in helping with this issue. I have a few questions about the issue. You mentioned default.qubit Is that under pennylane/devices/default_qubit.py file? If so, I would want to modify the DefaultQubit class? Since it's a device, then it should already have supports_operation, correct?

Thanks!

Colin-Orian avatar Jun 16 '22 15:06 Colin-Orian

Hi @Colin-Orian, yes you found the correct file. You can learn more about devices in this section of the docs. DefaultQubit inherits from QubitDevice which is a subclass of Device. In this part of the docs you can find the source code for supports_operation.

Please let me know if this helps!

CatalinaAlbornoz avatar Jun 16 '22 19:06 CatalinaAlbornoz

We renamed the CV operation to qml.QuadX and added qml.X as an alias for PauliX, so this issue is no longer valid.

albi3ro avatar Apr 22 '24 17:04 albi3ro