About cookies on this site Our websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising. For more information, please review your options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.
qiskit.converters.ast_to_dag
ast_to_dag(ast)
Build a DAGCircuit
object from an AST Node
object.
Parameters
ast (Program) – a Program Node of an AST (parser’s output)
Returns
the DAG representing an OpenQASM’s AST
Return type
Raises
QiskitError – if the AST is malformed.
Example
from qiskit.converters import ast_to_dag
from qiskit import qasm, QuantumCircuit, ClassicalRegister, QuantumRegister
q = QuantumRegister(3, 'q')
c = ClassicalRegister(3, 'c')
circ = QuantumCircuit(q, c)
circ.h(q[0])
circ.cx(q[0], q[1])
circ.measure(q[0], c[0])
circ.rz(0.5, q[1]).c_if(c, 2)
qasm_str = circ.qasm()
ast = qasm.Qasm(data=qasm_str).parse()
dag = ast_to_dag(ast)
Was this page helpful?
Report a bug or request content on GitHub.