# Simulating OpenQASM 2.0 in Qiskit?

I'm just getting started with OpenQASM, but I'm feeling a bit confused. Is there a way to run the .qasm file I've written in Qiskit (i.e. in Python), or is OpenQasm only meant to be used within the IBM Quantum experience?

You can use qasm files to create a quantum circuit, two ways : via the methods from_qasm_str or from_qasm_file on a QuantumCircuit. See the documentation about this. For example :

test = ''' OPENQASM 2.0;
include "qelib1.inc";

qreg q[2];
creg c[2];

h q[0];
cx q[0],q[1];
'''
from qiskit import QuantumCircuit
qc = QuantumCircuit.from_qasm_str(test)


This will create a QuantumCircuit from the str test. The same syntax work with the other method, just replace test with the path to the qasm file.

Hope this helps! :)

• Thank you so much! That appears to have worked. I do have another question though. How would I go about getting the state from this QuantumCircuit object? I've tried save_state() but that throws an error. Do I have to then run this on a simulator (such as aer) to be able to retrieve the state? Maybe this ought to be a separate post Aug 18 at 1:49
• You can find the answer in this tutorial :)
– Lena
Aug 18 at 7:39