-
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.
Add DAGDependencyV2 and Converters (#11705)
* Fix typing-extensions * Add dagdependency_v2 and converters * Add V2 tests * Cleanup testing * Move import * Add copy_empty_like and topological_op_nodes * Lint and providers update * Change to apply_operation_back * Fix converter init * Cleanup and remove indices methods * Change to _get_node and cleanup * Add reno * Fix node_id bug in dag_drawer * Lint * Convert to using leading _ for class and functions * Cleanup test file import * Fix converters * Restart CI * Remove reno and remove_ops functions and fix typo * Remove init entries for v2 * Remove meaningless methods These `quantum_successors` etc have no meaning in `DAGDependency` (and V2) since the edges don't carry the data that the `DAGCircuit` functions check for; `DAGDependency` is in part a deliberate erasure of this data. --------- Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
- Loading branch information
1 parent
46b12c5
commit 6cae4cf
Showing
7 changed files
with
1,198 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2020. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Helper function for converting a circuit to a dag dependency""" | ||
|
||
from qiskit.dagcircuit.dagdependency_v2 import _DAGDependencyV2 | ||
|
||
|
||
def _circuit_to_dagdependency_v2(circuit): | ||
"""Build a ``_DAGDependencyV2`` object from a :class:`~.QuantumCircuit`. | ||
Args: | ||
circuit (QuantumCircuit): the input circuit. | ||
Return: | ||
_DAGDependencyV2: the DAG representing the input circuit as a dag dependency. | ||
""" | ||
dagdependency = _DAGDependencyV2() | ||
dagdependency.name = circuit.name | ||
dagdependency.metadata = circuit.metadata | ||
dagdependency.calibrations = circuit.calibrations | ||
dagdependency.global_phase = circuit.global_phase | ||
|
||
dagdependency.add_qubits(circuit.qubits) | ||
dagdependency.add_clbits(circuit.clbits) | ||
|
||
for register in circuit.qregs: | ||
dagdependency.add_qreg(register) | ||
|
||
for register in circuit.cregs: | ||
dagdependency.add_creg(register) | ||
|
||
for instruction in circuit.data: | ||
dagdependency.apply_operation_back( | ||
instruction.operation, instruction.qubits, instruction.clbits | ||
) | ||
|
||
return dagdependency |
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,44 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2020. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Helper function for converting a dag circuit to a dag dependency""" | ||
from qiskit.dagcircuit.dagdependency_v2 import _DAGDependencyV2 | ||
|
||
|
||
def _dag_to_dagdependency_v2(dag): | ||
"""Build a ``_DAGDependencyV2`` object from a ``DAGCircuit``. | ||
Args: | ||
dag (DAGCircuit): the input dag. | ||
Return: | ||
_DAGDependencyV2: the DAG representing the input circuit as a dag dependency. | ||
""" | ||
dagdependency = _DAGDependencyV2() | ||
dagdependency.name = dag.name | ||
dagdependency.metadata = dag.metadata | ||
dagdependency.global_phase = dag.global_phase | ||
dagdependency.calibrations = dag.calibrations | ||
|
||
dagdependency.add_qubits(dag.qubits) | ||
dagdependency.add_clbits(dag.clbits) | ||
|
||
for register in dag.qregs.values(): | ||
dagdependency.add_qreg(register) | ||
|
||
for register in dag.cregs.values(): | ||
dagdependency.add_creg(register) | ||
|
||
for node in dag.topological_op_nodes(): | ||
dagdependency.apply_operation_back(node.op.copy(), node.qargs, node.cargs) | ||
|
||
return dagdependency |
Oops, something went wrong.