Convert quantum circuit from Pennylane to qasm language

I am so curious about converting quantum circuits from Pennylane to qasm language. Is there any method in Pennylane to do it?

Hi @sassan_moradi!

This can be done by following the example below:

import pennylane as qml

dev = qml.device("qiskit.aer", wires=1)

@qml.qnode(dev)
def f(x):
    qml.RX(x, wires=0)
    return qml.expval(qml.PauliZ(0))

f(0.3)

dev._circuit.qasm(formatted=True)

For this, you will need the PennyLane-Qiskit plugin. The code above works by simply converting to a Qiskit circuit and then using the Qiskit circuit’s qasm() method. This isn’t really a central feature of PennyLane, so please let us know if you encounter any troubles!

Thanks!

i will try with your example first. Thanks a lot.

Thanks @sassan_moradi!

Thanks again. it solved my problem " dev._circuit.qasm(formatted=True)".

That’s great, thanks @sassan_moradi!