Commit ba4dd7a
Add new API for inserting multiple operations into the
* Initial: Add `DAGCircuitConcat` struct and new insertion API.
- Add struct that allows continuous addition of instructions into the back of the `DAGCircuit` by performing edge modifications in the output nodes at the end of the additions.
- The new struct includes the following new methods:
- `push_operation_back` which pushes a valid `PackedInstruction` into the back of the `DAGCircuit`. It behaves very similarly to `push_back`.
- `apply_operation_back` which inserts a new operation into the back of the `DAGCircuit`. It has two variants which depend on the ownership of the bit indices (`Qubit`, `Clbit`).
- `pack_instruction`: private method that basically does just that, it creates a valid instance of `PackedInstruction` based on other provided atributes.
- Modified `DAGCircuit::extend` to use this new API, without any considerable losses.
* Add: `OwnedOrSlice<T>`
- Add struct that allows usage of both slice or owned collections of bit indices.
- Leverage use of `as_concat()` in `circuit_to_dag`.
* Add: Optional qargs/cargs in `apply_operation_back`
- Leverage usage of new methods in `UnitarySynthesis` after Qiskit#13141 merged.
* Fix: Leverage usage in `BasisTranslator`
* Fix: Replace `OnceCell` with `OnceLock`
* Fix: Remove `SliceOrOwned` in favor of `Cow`
* Fix: Expose the interners via references within `DAGCircuitConcat`.
* Refactor: `DAGCircuit::as_concat` to `DAGCircuit::into_concat`.
- Allow `DAGCircuitConcat` to take ownership of the original `DAGCircuit` it is being called from, and allow `DAGCircuitConcat::end` to return the original `DAGCircuit`.
- Bypass taking ownership of the `DAGCircuit` during `DAGCircuit::extend` calls by swapping with a temporary replacement.
* Fix: Remove inefficient code from `UnitarySynthesis`
- A previous commit added some inefficient code into the `apply_synth_dag` function in `UnitarySynthesis`. The newer code should be much simpler to use.
- Rename interner views in `DAGCircuitConcat` to match their `DAGCircuit` counterparts.
* Fix: Remove obsolete pytoken.
* Update crates/circuit/src/dag_circuit.rs
Co-authored-by: Kevin Hartman <[email protected]>
* Fix: Address comments from code review
- Create `_push_back` method to perform initial additions and parsing before pushing an instruction into the circuit. This will be used by both the `DAGCircuit` and the `DAGCircuitBuilder`.
- Fix `DAGCircuitBuilder::end` docstring.
- Remove `qarg/carg_interner_mut`, replaced by `insert_qargs/cargs`.
* Apply suggestions from code review
Co-authored-by: Kevin Hartman <[email protected]>
* Fix: Address review comments
- Rename `_push_back` to `get_classical_resources`.
- Rename variables to keep the naming scheme.
- Remove `increment_op` step from `get_classical_resources`.
* Fix: Limit `get_classical_resources` to only `Clbits` and `Vars`.
- Remove `DAGNodeInfo`.
* Fix: Missing `py` token added after modification to `DAGCircuit::num_vars()`
* Apply suggestions from code review
Co-authored-by: Kevin Hartman <[email protected]>
* Fix: Remove usage of `end`.
- Remove mutably borrowing the `DAGCircuit` in `get_classical_resources`.
---------
Co-authored-by: Kevin Hartman <[email protected]>DAGCircuit in Rust. (Qiskit#13335)1 parent f71d201 commit ba4dd7a
File tree
3 files changed
+351
-243
lines changed- crates
- accelerate/src
- basis/basis_translator
- circuit/src
3 files changed
+351
-243
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
460 | 461 | | |
461 | 462 | | |
462 | 463 | | |
463 | | - | |
| 464 | + | |
| 465 | + | |
464 | 466 | | |
465 | 467 | | |
466 | 468 | | |
| |||
504 | 506 | | |
505 | 507 | | |
506 | 508 | | |
507 | | - | |
| 509 | + | |
508 | 510 | | |
509 | 511 | | |
510 | | - | |
511 | | - | |
| 512 | + | |
| 513 | + | |
512 | 514 | | |
513 | 515 | | |
514 | 516 | | |
515 | | - | |
| 517 | + | |
516 | 518 | | |
517 | | - | |
| 519 | + | |
518 | 520 | | |
519 | 521 | | |
520 | 522 | | |
521 | 523 | | |
522 | | - | |
| 524 | + | |
523 | 525 | | |
524 | 526 | | |
525 | | - | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
539 | 531 | | |
540 | 532 | | |
541 | 533 | | |
| |||
547 | 539 | | |
548 | 540 | | |
549 | 541 | | |
550 | | - | |
| 542 | + | |
551 | 543 | | |
552 | 544 | | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
567 | 549 | | |
568 | 550 | | |
569 | 551 | | |
| |||
578 | 560 | | |
579 | 561 | | |
580 | 562 | | |
581 | | - | |
| 563 | + | |
582 | 564 | | |
583 | 565 | | |
584 | 566 | | |
585 | 567 | | |
586 | 568 | | |
587 | 569 | | |
588 | | - | |
| 570 | + | |
589 | 571 | | |
590 | 572 | | |
591 | 573 | | |
| |||
594 | 576 | | |
595 | 577 | | |
596 | 578 | | |
597 | | - | |
598 | | - | |
| 579 | + | |
599 | 580 | | |
600 | 581 | | |
601 | 582 | | |
602 | 583 | | |
603 | | - | |
| 584 | + | |
604 | 585 | | |
605 | 586 | | |
606 | 587 | | |
| |||
619 | 600 | | |
620 | 601 | | |
621 | 602 | | |
622 | | - | |
623 | | - | |
| 603 | + | |
| 604 | + | |
624 | 605 | | |
625 | 606 | | |
626 | 607 | | |
| |||
641 | 622 | | |
642 | 623 | | |
643 | 624 | | |
644 | | - | |
645 | 625 | | |
646 | 626 | | |
647 | 627 | | |
648 | | - | |
649 | | - | |
| 628 | + | |
| 629 | + | |
650 | 630 | | |
651 | 631 | | |
652 | 632 | | |
653 | | - | |
| 633 | + | |
654 | 634 | | |
655 | | - | |
| 635 | + | |
656 | 636 | | |
657 | 637 | | |
658 | 638 | | |
| |||
665 | 645 | | |
666 | 646 | | |
667 | 647 | | |
668 | | - | |
669 | | - | |
| 648 | + | |
| 649 | + | |
670 | 650 | | |
671 | 651 | | |
672 | 652 | | |
| |||
749 | 729 | | |
750 | 730 | | |
751 | 731 | | |
752 | | - | |
753 | | - | |
| 732 | + | |
| 733 | + | |
754 | 734 | | |
755 | 735 | | |
756 | 736 | | |
757 | | - | |
| 737 | + | |
758 | 738 | | |
759 | | - | |
| 739 | + | |
760 | 740 | | |
761 | 741 | | |
762 | 742 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| |||
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
| 24 | + | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
134 | 133 | | |
135 | 134 | | |
136 | 135 | | |
137 | | - | |
| 136 | + | |
138 | 137 | | |
139 | 138 | | |
140 | 139 | | |
| |||
145 | 144 | | |
146 | 145 | | |
147 | 146 | | |
148 | | - | |
| 147 | + | |
149 | 148 | | |
150 | 149 | | |
151 | 150 | | |
| |||
158 | 157 | | |
159 | 158 | | |
160 | 159 | | |
161 | | - | |
| 160 | + | |
162 | 161 | | |
163 | 162 | | |
164 | 163 | | |
165 | | - | |
166 | 164 | | |
167 | 165 | | |
168 | 166 | | |
| |||
212 | 210 | | |
213 | 211 | | |
214 | 212 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
221 | 220 | | |
222 | | - | |
223 | | - | |
224 | | - | |
| 221 | + | |
| 222 | + | |
225 | 223 | | |
226 | | - | |
227 | 224 | | |
228 | 225 | | |
229 | 226 | | |
| |||
374 | 371 | | |
375 | 372 | | |
376 | 373 | | |
377 | | - | |
| 374 | + | |
378 | 375 | | |
379 | 376 | | |
380 | 377 | | |
| 378 | + | |
381 | 379 | | |
382 | 380 | | |
383 | 381 | | |
| |||
388 | 386 | | |
389 | 387 | | |
390 | 388 | | |
391 | | - | |
| 389 | + | |
392 | 390 | | |
393 | 391 | | |
394 | 392 | | |
| 393 | + | |
395 | 394 | | |
396 | 395 | | |
397 | 396 | | |
| |||
409 | 408 | | |
410 | 409 | | |
411 | 410 | | |
412 | | - | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
413 | 414 | | |
414 | 415 | | |
415 | 416 | | |
| |||
1071 | 1072 | | |
1072 | 1073 | | |
1073 | 1074 | | |
1074 | | - | |
| 1075 | + | |
1075 | 1076 | | |
| 1077 | + | |
1076 | 1078 | | |
1077 | 1079 | | |
1078 | 1080 | | |
| |||
1081 | 1083 | | |
1082 | 1084 | | |
1083 | 1085 | | |
1084 | | - | |
1085 | | - | |
| 1086 | + | |
| 1087 | + | |
1086 | 1088 | | |
1087 | | - | |
| 1089 | + | |
1088 | 1090 | | |
1089 | 1091 | | |
1090 | 1092 | | |
| |||
1162 | 1164 | | |
1163 | 1165 | | |
1164 | 1166 | | |
1165 | | - | |
| 1167 | + | |
1166 | 1168 | | |
1167 | | - | |
| 1169 | + | |
1168 | 1170 | | |
1169 | 1171 | | |
1170 | 1172 | | |
| |||
0 commit comments