Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support non-DFG circuits #391

Merged
merged 3 commits into from
Jun 17, 2024
Merged

fix: Support non-DFG circuits #391

merged 3 commits into from
Jun 17, 2024

Conversation

aborgna-q
Copy link
Collaborator

@aborgna-q aborgna-q commented Jun 7, 2024

Followup to #390.
Fixes #389.
Closes #385.
Blocked by CQCL/hugr#1175.

Fixes support for non-Dfg circuits and circuits with a non-root parent:

Adds a Circuit::extract_dfg(&self) function that extracts the circuit into a new hugr with a DFG operation at the root.
In some cases, like in a CFG DataflowBlock node, this requires some changes to the definition to eliminate the output sum type.
Here I only implemented it for the kind of blocks produced by guppy. We could replace the manual implementation once CQCL/hugr#818 gets implemented.

With this we can now fix #389 by extracting the circuit before using it as a replacement in SimpleReplacement::create_simple_replacement.

Replaces DfgBuilder with FunctionBuilder where possible, so we can use named circuits in the tests.
(This failed before due to the bug in CircuitRewrite).

@aborgna-q aborgna-q changed the title fix: Test support for non-DFG circuits fix: non-DFG circuits support Jun 7, 2024
@aborgna-q aborgna-q changed the title fix: non-DFG circuits support fix: Support non-DFG circuits Jun 7, 2024
@aborgna-q aborgna-q marked this pull request as ready for review June 7, 2024 13:43
@aborgna-q aborgna-q force-pushed the ab/funcdefn-circuits branch from 8af63fe to 4ddbc5b Compare June 10, 2024 14:30
@aborgna-q aborgna-q force-pushed the ab/funcdefn-circuits branch from 4ddbc5b to 1823489 Compare June 11, 2024 14:19
Base automatically changed from ab/circuit-names to main June 17, 2024 11:27
@aborgna-q aborgna-q force-pushed the ab/funcdefn-circuits branch from 1823489 to 741e264 Compare June 17, 2024 12:26
Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 43.85965% with 64 lines in your changes missing coverage. Please review.

Project coverage is 80.77%. Comparing base (f18aa4d) to head (b0483ff).

Files Patch % Lines
tket2/src/circuit/extract_dfg.rs 22.97% 56 Missing and 1 partial ⚠️
tket2/src/circuit.rs 66.66% 3 Missing and 1 partial ⚠️
tket2/src/utils.rs 60.00% 0 Missing and 2 partials ⚠️
tket2/src/rewrite.rs 95.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #391      +/-   ##
==========================================
- Coverage   81.32%   80.77%   -0.56%     
==========================================
  Files          53       54       +1     
  Lines        5184     5280      +96     
  Branches     4708     4804      +96     
==========================================
+ Hits         4216     4265      +49     
- Misses        767      811      +44     
- Partials      201      204       +3     
Flag Coverage Δ
python 96.00% <ø> (ø)
rust 79.26% <43.85%> (-0.58%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aborgna-q aborgna-q requested a review from ss2165 June 17, 2024 13:13
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

the rewrite from cfg block to dfg without tag/unit type is indeed a bit hacky... even a simple change like guppy outputting just the Unit value as a const (rather than a Tag node) would break it. But I think it's ok for now.

@aborgna-q aborgna-q added this pull request to the merge queue Jun 17, 2024
Merged via the queue into main with commit 39057d2 Jun 17, 2024
15 of 16 checks passed
@aborgna-q aborgna-q deleted the ab/funcdefn-circuits branch June 17, 2024 14:45
@hugrbot hugrbot mentioned this pull request Jun 17, 2024
@hugrbot hugrbot mentioned this pull request Aug 1, 2024
github-merge-queue bot pushed a commit that referenced this pull request Aug 1, 2024
## 🤖 New release
* `tket2`: 0.1.0-alpha.2 -> 0.1.0
* `tket2-hseries`: 0.1.0

<details><summary><i><b>Changelog</b></i></summary><p>

## `tket2`
<blockquote>

##
[0.1.0](tket2-v0.1.0-alpha.2...tket2-v0.1.0)
- 2024-08-01

### Bug Fixes
- Single source of truth for circuit names, and better circuit errors
([#390](#390))
- Support non-DFG circuits
([#391](#391))
- Portmatching not matching const edges
([#444](#444))
- Pattern matcher discriminating on opaqueOp description
([#441](#441))
- `extract_dfg` inserting the output node with an invalid child order
([#442](#442))
- Recompile ecc sets after
[#441](#441)
([#484](#484))

### Documentation
- Update tket2-py readme
([#431](#431))
- Better error reporting in portmatching
([#437](#437))
- Improved multi-threading docs for Badger
([#495](#495))

### New Features
- `Circuit::operations` ([#395](#395))
- tuple unpack rewrite ([#406](#406))
- guppy → pytket conversion
([#407](#407))
- Drop linear bits, improve pytket encoding/decoding
([#420](#420))
- *(py)* Allow using `Tk2Op`s in the builder
([#436](#436))
- Initial support for `TailLoop` as circuit parent
([#417](#417))
- Support tuple unpacking with multiple unpacks
([#470](#470))
- Partial tuple unpack ([#475](#475))
- [**breaking**] Compress binary ECCs using zlib
([#498](#498))
- Add timeout options and stats to Badger
([#496](#496))
- Expose advanced Badger timeout options to tket2-py
([#506](#506))

### Refactor
- [**breaking**] Simplify tket1 conversion errors
([#408](#408))
- Cleanup tket1 serialized op structures
([#419](#419))

### Testing
- Add coverage for Badger split circuit multi-threading
([#505](#505))
</blockquote>

## `tket2-hseries`
<blockquote>

##
[0.1.0](https://github.com/CQCL/tket2/releases/tag/tket2-hseries-v0.1.0)
- 2024-08-01

### New Features
- [**breaking**] init tket2-hseries
([#368](#368))
- *(tket2-hseries)* Add `tket2.futures` Hugr extension
([#471](#471))
- Add lazify-measure pass
([#482](#482))
- add results extensions
([#494](#494))
- *(tket2-hseries)* [**breaking**] Add `HSeriesPass`
([#487](#487))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

---------

Co-authored-by: Douglas Wilson <[email protected]>
@hugrbot hugrbot mentioned this pull request Aug 1, 2024
github-merge-queue bot pushed a commit that referenced this pull request Aug 15, 2024
## 🤖 New release
* `tket2`: 0.1.0 -> 0.1.1
* `tket2-hseries`: 0.1.0 -> 0.1.1

<details><summary><i><b>Changelog</b></i></summary><p>

## `tket2`
<blockquote>

##
[0.1.0](tket2-v0.1.0-alpha.2...tket2-v0.1.0)
- 2024-08-01

### Bug Fixes
- Single source of truth for circuit names, and better circuit errors
([#390](#390))
- Support non-DFG circuits
([#391](#391))
- Portmatching not matching const edges
([#444](#444))
- Pattern matcher discriminating on opaqueOp description
([#441](#441))
- `extract_dfg` inserting the output node with an invalid child order
([#442](#442))
- Recompile ecc sets after
[#441](#441)
([#484](#484))

### Documentation
- Update tket2-py readme
([#431](#431))
- Better error reporting in portmatching
([#437](#437))
- Improved multi-threading docs for Badger
([#495](#495))

### New Features
- `Circuit::operations` ([#395](#395))
- tuple unpack rewrite ([#406](#406))
- guppy → pytket conversion
([#407](#407))
- Drop linear bits, improve pytket encoding/decoding
([#420](#420))
- *(py)* Allow using `Tk2Op`s in the builder
([#436](#436))
- Initial support for `TailLoop` as circuit parent
([#417](#417))
- Support tuple unpacking with multiple unpacks
([#470](#470))
- Partial tuple unpack ([#475](#475))
- [**breaking**] Compress binary ECCs using zlib
([#498](#498))
- Add timeout options and stats to Badger
([#496](#496))
- Expose advanced Badger timeout options to tket2-py
([#506](#506))

### Refactor
- [**breaking**] Simplify tket1 conversion errors
([#408](#408))
- Cleanup tket1 serialized op structures
([#419](#419))

### Testing
- Add coverage for Badger split circuit multi-threading
([#505](#505))
</blockquote>

## `tket2-hseries`
<blockquote>

##
[0.1.1](tket2-hseries-v0.1.0...tket2-hseries-v0.1.1)
- 2024-08-15

### New Features
- *(tket2-hseries)* make result operation internals public
([#542](#542))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

---------

Co-authored-by: Seyon Sivarajah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CircuitRewrite does only support Dfg-rooted circuits Test FuncDefn circuits instead of DFGs
2 participants