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

feat: rewrite tracing #267

Merged
merged 5 commits into from
Dec 14, 2023
Merged

feat: rewrite tracing #267

merged 5 commits into from
Dec 14, 2023

Conversation

aborgna-q
Copy link
Collaborator

Optionally store metadata about the rewrites applied to a circuit.

If the rewrite-tracing feature is disabled, this has no effect on the runtime.

If the feature is enabled, circuits must opt-in to the tracing by calling RewriteTracer::enable_rewrite_tracing.

Closes #216

@aborgna-q aborgna-q changed the title Feat/rewrite tracing feat: rewrite tracing Dec 14, 2023
Copy link

codecov bot commented Dec 14, 2023

Codecov Report

Attention: 17 lines in your changes are missing coverage. Please review.

Comparison is base (c2875d8) 83.44% compared to head (e64af83) 83.40%.

❗ Current head e64af83 differs from pull request most recent head 69c4af9. Consider uploading reports for the commit 69c4af9 to get more accurate results

Files Patch % Lines
tket2/src/optimiser/badger.rs 0.00% 6 Missing ⚠️
tket2/src/rewrite/trace.rs 90.19% 3 Missing and 2 partials ⚠️
tket2/src/optimiser/badger/log.rs 70.00% 3 Missing ⚠️
tket2/src/rewrite/strategy.rs 88.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #267      +/-   ##
==========================================
- Coverage   83.44%   83.40%   -0.04%     
==========================================
  Files          34       35       +1     
  Lines        4191     4285      +94     
  Branches     4075     4169      +94     
==========================================
+ Hits         3497     3574      +77     
- Misses        511      526      +15     
- Partials      183      185       +2     

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

///
/// Note that circuits must be explicitly enabled for rewrite tracing by calling
/// [`RewriteTracer::enable_rewrite_tracing`].
pub const REWRITE_TRACING_ENABLED: bool = cfg!(feature = "rewrite-tracing");
Copy link
Member

Choose a reason for hiding this comment

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

is rust analyzer etc. good enough to ignore code guarded by this constant?

Copy link
Collaborator Author

@aborgna-q aborgna-q Dec 14, 2023

Choose a reason for hiding this comment

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

rust analyser checks the default features unless configured differently, but this should work the same as any const flag.

}
let meta = self.get_metadata(self.root(), METADATA_REWRITES)?;
let rewrites = meta.as_array()?;
Some(rewrites.iter().map_into().collect_vec())
Copy link
Member

Choose a reason for hiding this comment

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

could return a &[RewriteTrace]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not possible with the .map_into, but we could return an impl Iterator once RPITIT` is here...

@ss2165
Copy link
Member

ss2165 commented Dec 14, 2023

There doesn't seem to be any key or namespace reservation happening in the metadata to denote a section as being for rewrites?

@aborgna-q
Copy link
Collaborator Author

There is no structure for the metadata namespace yet. There's a discussion thread for that: CQCL/hugr#268

@aborgna-q aborgna-q added this pull request to the merge queue Dec 14, 2023
Merged via the queue into main with commit f04e815 Dec 14, 2023
9 checks passed
@aborgna-q aborgna-q deleted the feat/rewrite-tracing branch December 14, 2023 17:34
github-merge-queue bot pushed a commit that referenced this pull request May 24, 2024
## 🤖 New release
* `tket2`: 0.1.0-alpha.1

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

## `tket2`
<blockquote>

##
[0.0.0-alpha.1](https://github.com/CQCL/tket2/releases/tag/tket2-v0.0.0-alpha.1)
- 2024-05-24

### Bug Fixes
- Check for rewrite composition in badger
([#255](#255))
- induced cycles in depth optimisation
([#264](#264))
- Encode opaque symbolic constants
([#273](#273))
- Correctly detect custom ops by name
([#281](#281))
- Track input linear units in `Command`
([#310](#310))
- Don't convert tket2 measurements into tket1 ops
([#331](#331))

### Documentation
- Expand the main module and README docs
([#298](#298))

### New Features
- add angle type to tket2 extension
([#231](#231))
- bindings for circuit cost and hash
([#252](#252))
- Implement `PyErr` conversion locally in `tket2-py`
([#258](#258))
- Add a "progress timeout" to badger
([#259](#259))
- [**breaking**] Add lexicographic cost
([#270](#270))
- rewrite tracing ([#267](#267))
- Move pre/post rewrite cost to the RewriteStrategy API
([#276](#276))
- [**breaking**] Lexicographic cost fn
([#277](#277))
- Return rewrite strategies as a generator
([#275](#275))
- add qalloc, qfree, reset ops
([#284](#284))
- [**breaking**] Support any ops in portmatching
([#293](#293))
- Add `PatternMatch::nodes` and `subcircuit` + matching example
([#299](#299))
- Use `IncomingPort` and `OutgoingPort` instead of `Port` where
possible. ([#296](#296))
- expose Tk2Op name ([#307](#307))

### Refactor
- Move tket2 code to a workspace member
([#210](#210))
- Restructure the python code
([#211](#211))
- s/taso/badger/ ([#228](#228))
- Move python bindings from `tket2` to `tket2-py`
([#235](#235))
- rename t2op ([#256](#256))

### Testing
- Add small parallel badger test
([#237](#237))
- fix non-deterministic badger test
([#245](#245))
</blockquote>


</p></details>

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

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Agustin Borgna <agustin.borgna@quantinuum.com>
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.

Rewrite tracing via metadata
2 participants