-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added classical_predecessors method (#9980)
* Added classical_predecessors method * add accesed method * Added classsical_successor method * Added classical predecessors and successors method * added tol command * successors method * add test classical_successor method * changed DagOutNode * Apply suggestions from code review from @atharva-satpute. Thanks! Co-authored-by: atharva-satpute <55058959+atharva-satpute@users.noreply.github.com> * add assertRaises on test methods * correct typo variable name * change the descrption * change the text on the example * change the format of yaml * new example * new suggestions * fix test * new test example and change the release note * Fixup release note * Fix typo --------- Co-authored-by: Maldoalberto <amaldonador1300@alumno.ipn.mx> Co-authored-by: Maldoalberto <Alberto.Maldonado.Romo@ibm.com> Co-authored-by: Luciano Bello <bel@zurich.ibm.com> Co-authored-by: atharva-satpute <55058959+atharva-satpute@users.noreply.github.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
- Loading branch information
1 parent
f995814
commit 2ba2984
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
releasenotes/notes/add-classical-predecessors-9ecef0561822e934.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
features: | ||
- | | ||
Added :meth:`.DAGCircuit.classical_predecessors` and | ||
:meth:`.DAGCircuit.classical_successors`, an alternative to select the classical | ||
wires without having to go to the inner graph object directly of a node in the DAG. | ||
The following example illustrates the new functionality:: | ||
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister | ||
from qiskit.converters import circuit_to_dag | ||
from qiskit.circuit.library import RZGate | ||
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) | ||
circ.measure(q[1], c[0]) | ||
dag = circuit_to_dag(circ) | ||
rz_node = dag.op_nodes(RZGate)[0] | ||
# Contains the "measure" on clbit 0, and the "wire start" nodes for clbits 1 and 2. | ||
classical_predecessors = list(dag.classical_predecessors(rz_node)) | ||
# Contains the "measure" on clbit 0, and the "wire end" nodes for clbits 1 and 2. | ||
classical_successors = list(dag.classical_successors(rz_node)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters