qiskit
qiskit copied to clipboard
Update _update_edges in DAGDependencyV2
Summary
Updates _update_edges
Details and comments
This PR refactors the _update_edges
method in DAGdependencyV2
, which creates edges based on non-commutativity. This is built on top of #11705 and should be on hold until that PR merges. These changes accomplish the following,
- Previously the method was based on iterating over node indices. This works fine if the dag is created using one of the converters and nodes are never removed. This new version is based on node objects and should allow for removal of nodes and subsequent additions.
- Now all method calls that pass
node
use the node object and there is no longer any iterating over node_id's. This more closely matches the wayDAGCircuit
works. This allows for elimination of the_get_node
/get_node
method which was unique to the dag dependencies.
Here are some additional local test results using circuit_to_dagdependency
and circuit_to_dagdependency_v2
.
Below "with" or "without" means create_preds_and_succs was set to True or False in V1. (not applicable to V2)
Using 20 qubits and 10,000 gates in a random Clifford circuit,
V1 with V1 without V2 (this PR)
Memory 3.9GB 160MB 152MB
Time 1 min 54 sec 1 min 15 sec 30 sec
Using 100 qubits and 20,000 gates,
V1 with V1 without V2 (this PR)
Memory (Memory overrun) 176MB 186MB
Time 6 min 16 sec 2 min 11 sec
One or more of the the following people are requested to review this:
- @enavarro51
-
@Qiskit/terra-core
Pull Request Test Coverage Report for Build 7976669756
Warning: This coverage report may be inaccurate.
This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
- For more information on this, see Tracking coverage changes with pull request builds.
- To avoid this issue with future PRs, see these Recommended CI Configurations.
- For a quick fix, rebase this PR at GitHub. Your next report should be accurate.
Details
- -85 of 293 (70.99%) changed or added relevant lines in 6 files are covered.
- 221 unchanged lines in 31 files lost coverage.
- Overall coverage increased (+0.02%) to 89.22%
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
---|---|---|---|
qiskit/visualization/dag_visualization.py | 0 | 3 | 0.0% |
qiskit/dagcircuit/dagdependency_v2.py | 171 | 253 | 67.59% |
<!-- | Total: | 208 | 293 |
Files with Coverage Reduction | New Missed Lines | % |
---|---|---|
crates/qasm2/src/expr.rs | 1 | 93.81% |
qiskit/primitives/base/base_estimator.py | 1 | 97.44% |
qiskit/primitives/base/base_sampler.py | 1 | 96.97% |
qiskit/primitives/statevector_sampler.py | 1 | 99.1% |
qiskit/synthesis/clifford/clifford_decompose_ag.py | 1 | 98.72% |
qiskit/synthesis/clifford/clifford_decompose_full.py | 1 | 87.5% |
qiskit/synthesis/linear/cnot_synth.py | 1 | 98.0% |
qiskit/circuit/duration.py | 2 | 70.27% |
qiskit/synthesis/clifford/clifford_decompose_greedy.py | 2 | 98.88% |
qiskit/synthesis/linear/linear_depth_lnn.py | 2 | 98.33% |
<!-- | Total: | 221 |
Totals | |
---|---|
Change from base Build 7893751411: | 0.02% |
Covered Lines: | 59116 |
Relevant Lines: | 66259 |
💛 - Coveralls
With the new GitHub features, we can now easily draw graphs and flowcharts. Just for fun, an illustration of adding a node to DAGDependency.
flowchart LR
subgraph before
direction LR
A["X(0)"] --> C["Y(0)"]
B["X(0)"] --> C
C --> F["Z(0)"]
end
subgraph after
direction LR
A2["X(0)"] --> C2["Y(0)"]
B2["X(0)"] --> C2
C2 --> F2["Z(0)"]
C2 --> H2["Z(0)"]
end
subgraph new node
H["Z(0)"]
end
before -->|adding new node to dag dependency| after
The 3X improvement is not a function of this PR, but of the 2 PRs combined. It's still somewhat of a mystery to me. The same number of edges are created. I tried a quick and dirty change to dagdependency.py
to use DAGOpNode
. I thought maybe the _key_cache
and find_bit
might have some effect, but there was only a minimal difference. Open to suggestions here.
I'm closing this since this was an early attempt at optimizing the DAGDependencyV2
conversion process. Most of this was superceded by #11705 and a future PR which will incorporate more rustworkx optimizations.