I can find many qasm examples. How can I run them on different IBMQ devices?
Asked
Active
Viewed 2,765 times
3 Answers
9
This is a example for loading QASM, executing and displaying the result.
from qiskit import QuantumCircuit, Aer, execute
qasm_str = """OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];
h q[0];
cx q[0],q[1];
measure q -> c;
"""
# From str.
qc = QuantumCircuit.from_qasm_str(qasm_str)
# If you want to read from file, use instead
# qc = QuantumCircuit.from_qasm_file("/path/to/file.qasm")
# You can choose other backend also.
backend = Aer.get_backend("qasm_simulator")
# Execute the circuit and show the result.
job = execute(qc, backend)
result = job.result()
print(result.get_counts())
gyu-don
- 324
- 1
- 5
7
The easiest way is to use the QuantumCircuit methods QuantumCircuit.from_qasm_file() or QuantumCircuit.from_qasm_str() depending on if your loading the QASM from a file or Python string, respectively.
Paul Nation
- 2,289
- 9
- 8