Commit 524fc74
committed
Skip decomposer construction in consolidate blocks with force_consolidate
In the recently merged Qiskit#16075 a default decomposer was added to the
consolidate block pass if the `force_consolidate` flag was set. This was
intended to enable running the pass in the absence of the options
required to configure a decomposer. If the force consolidate flag is set
we don't need a two qubit decomposer configured since we're always going
to consolidate a 2q block of > 1 gate. However, that fix was incomplete
because we don't want to use a decomposer if force_consolidate is set to
True. The 2q decomposer is used to compute the number of basis gates for
a 2q decomposition of the unitary based on the unitary's coordinates in
the weyl chamber. This basis gate count is then used as a heuristic in
the pass on whether to consolidate the block to a UnitaryGate or not.
Specifically, if the number of basis gates for the weyl coordinates is
less than the number of basis gates in the block then we consolidate
the block into a `UnitaryGate`. With `force_consolidate=True` all of this
work, including the initialization of the decomposers (which isn't
free), is wasted since we know we're going to consolidate.
This commit adjusts the logic in the pass so that the decomposer is
set to None when `force_consolidate=True` and the pass skips all usage
of the decomposer internally when force_consolidate is set to True.
Internally the rust code of the pass isn't handling the interface as
ideally as I would like. The rust interface I'd like is to define
the decomposer interface as something like:
```rust
enum DecomposerInput {
ForceConsolidate,
Decomposer(DecomposerType),
}
```
and removing the dedicated force_consolidate argument to make the use
of a decomposer and force consolidate mutally exclusive.
However, this isn't compatible with the pyo3 boundary layer. Since the
inner function of consolidate blocks is oddly the `py_` function to
avoid a larger refactor this opted to just make the decomposer arg an
`Option<DecomposerType>` and do a runtime check around the value and
`force_consolidate`. This has some additional overhead but in practice
it's negligible.1 parent 56beeb8 commit 524fc74
2 files changed
Lines changed: 62 additions & 30 deletions
File tree
- crates/transpiler/src/passes
- qiskit/transpiler/passes/optimization
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
| 226 | + | |
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
235 | 240 | | |
236 | 241 | | |
237 | 242 | | |
| |||
408 | 413 | | |
409 | 414 | | |
410 | 415 | | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
419 | 433 | | |
420 | 434 | | |
421 | 435 | | |
| |||
559 | 573 | | |
560 | 574 | | |
561 | 575 | | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
575 | 604 | | |
576 | 605 | | |
577 | 606 | | |
| |||
Lines changed: 11 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | 126 | | |
132 | 127 | | |
133 | | - | |
| 128 | + | |
| 129 | + | |
134 | 130 | | |
135 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
136 | 135 | | |
137 | 136 | | |
138 | 137 | | |
139 | 138 | | |
140 | 139 | | |
141 | 140 | | |
142 | 141 | | |
143 | | - | |
| 142 | + | |
144 | 143 | | |
145 | 144 | | |
146 | 145 | | |
| |||
153 | 152 | | |
154 | 153 | | |
155 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | | - | |
| 161 | + | |
159 | 162 | | |
160 | 163 | | |
161 | 164 | | |
| |||
0 commit comments