Circuit Converters (qiskit.converters
)#
- qiskit.converters.circuit_to_dag(circuit, copy_operations=True, *, qubit_order=None, clbit_order=None)[código fonte]#
Build a
DAGCircuit
object from aQuantumCircuit
.- Parâmetros:
circuit (QuantumCircuit) – the input circuit.
copy_operations (bool) – Deep copy the operation objects in the
QuantumCircuit
for the outputDAGCircuit
. This should only be set toFalse
if the inputQuantumCircuit
will not be used anymore as the operations in the outputDAGCircuit
will be shared instances and modifications to operations in theDAGCircuit
will be reflected in theQuantumCircuit
(and vice versa).qubit_order (Iterable[Qubit] or None) – the order that the qubits should be indexed in the output DAG. Defaults to the same order as in the circuit.
clbit_order (Iterable[Clbit] or None) – the order that the clbits should be indexed in the output DAG. Defaults to the same order as in the circuit.
- Retorno:
the DAG representing the input circuit.
- Tipo de retorno:
- Levanta:
ValueError – if the
qubit_order
orclbit_order
parameters do not match the bits in the circuit.
Example
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit from qiskit.dagcircuit import DAGCircuit from qiskit.converters import circuit_to_dag 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) dag = circuit_to_dag(circ)
- qiskit.converters.dag_to_circuit(dag, copy_operations=True)[código fonte]#
Build a
QuantumCircuit
object from aDAGCircuit
.- Parâmetros:
dag (DAGCircuit) – the input dag.
copy_operations (bool) – Deep copy the operation objects in the
DAGCircuit
for the outputQuantumCircuit
. This should only be set toFalse
if the inputDAGCircuit
will not be used anymore as the operations in the outputQuantumCircuit
will be shared instances and modifications to operations in theDAGCircuit
will be reflected in theQuantumCircuit
(and vice versa).
- Retorno:
the circuit representing the input dag.
- Tipo de retorno:
Example
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit from qiskit.dagcircuit import DAGCircuit from qiskit.converters import circuit_to_dag from qiskit.circuit.library.standard_gates import CHGate, U2Gate, CXGate from qiskit.converters import dag_to_circuit 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) dag = circuit_to_dag(circ) circuit = dag_to_circuit(dag) circuit.draw('mpl')
- qiskit.converters.circuit_to_instruction(circuit, parameter_map=None, equivalence_library=None, label=None)[código fonte]#
Build an
Instruction
object from aQuantumCircuit
.The instruction is anonymous (not tied to a named quantum register), and so can be inserted into another circuit. The instruction will have the same string name as the circuit.
- Parâmetros:
circuit (QuantumCircuit) – the input circuit.
parameter_map (dict) – For parameterized circuits, a mapping from parameters in the circuit to parameters to be used in the instruction. If None, existing circuit parameters will also parameterize the instruction.
equivalence_library (EquivalenceLibrary) – Optional equivalence library where the converted instruction will be registered.
label (str) – Optional instruction label.
- Levanta:
QiskitError – if parameter_map is not compatible with circuit
- Retorno:
an instruction equivalent to the action of the input circuit. Upon decomposition, this instruction will yield the components comprising the original circuit.
- Tipo de retorno:
Example
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit from qiskit.converters import circuit_to_instruction 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) circuit_to_instruction(circ)
- qiskit.converters.circuit_to_gate(circuit, parameter_map=None, equivalence_library=None, label=None)[código fonte]#
Build a
Gate
object from aQuantumCircuit
.The gate is anonymous (not tied to a named quantum register), and so can be inserted into another circuit. The gate will have the same string name as the circuit.
- Parâmetros:
circuit (QuantumCircuit) – the input circuit.
parameter_map (dict) – For parameterized circuits, a mapping from parameters in the circuit to parameters to be used in the gate. If None, existing circuit parameters will also parameterize the Gate.
equivalence_library (EquivalenceLibrary) – Optional equivalence library where the converted gate will be registered.
label (str) – Optional gate label.
- Levanta:
QiskitError – if circuit is non-unitary or if parameter_map is not compatible with circuit
- Retorno:
a Gate equivalent to the action of the input circuit. Upon decomposition, this gate will yield the components comprising the original circuit.
- Tipo de retorno:
- qiskit.converters.ast_to_dag(ast)[código fonte]#
Build a
DAGCircuit
object from an ASTNode
object.- Parâmetros:
ast (Program) – a Program Node of an AST (parser’s output)
- Retorno:
the DAG representing an OpenQASM’s AST
- Tipo de retorno:
- Levanta:
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)
- qiskit.converters.dagdependency_to_circuit(dagdependency)[código fonte]#
Build a
QuantumCircuit
object from aDAGDependency
.- Parâmetros:
dagdependency (DAGDependency) – the input dag.
- Retorno:
the circuit representing the input dag dependency.
- Tipo de retorno:
- qiskit.converters.circuit_to_dagdependency(circuit, create_preds_and_succs=True)[código fonte]#
Build a
DAGDependency
object from aQuantumCircuit
.- Parâmetros:
circuit (QuantumCircuit) – the input circuit.
create_preds_and_succs (bool) – whether to construct lists of predecessors and successors for every node.
- Retorno:
the DAG representing the input circuit as a dag dependency.
- Tipo de retorno:
- qiskit.converters.dag_to_dagdependency(dag, create_preds_and_succs=True)[código fonte]#
Build a
DAGDependency
object from aDAGCircuit
.- Parâmetros:
dag (DAGCircuit) – the input dag.
create_preds_and_succs (bool) – whether to construct lists of predecessors and successors for every node.
- Retorno:
the DAG representing the input circuit as a dag dependency.
- Tipo de retorno:
- qiskit.converters.dagdependency_to_dag(dagdependency)[código fonte]#
Build a
DAGCircuit
object from aDAGDependency
.- Parâmetros:
dependency (dag) – the input dag.
- Retorno:
the DAG representing the input circuit.
- Tipo de retorno: