Skip to content

Conversation

lmondada
Copy link
Contributor

@lmondada lmondada commented Feb 18, 2025

I'm putting this out here for discussion. My main question: how should I expose the hugr-like interface of CircuitHistory?. I've proposed an implementation of HugrView on a wrapper type ExperimentalHugrWrapper of the circuit history. See src/diff/experimental.rs.

A CircuitHistory is always equivalent to a valid Hugr (see CircuitHistory::extract_hugr), but implementing HugrView is difficult because

  • there is no "base hugr", so implementing HugrInternals is impossible. This could be implemented if the base hugr was node specific, i.e. fn base_hugr(&self, node: Node) -> &Hugr
  • the hugr::Node type is fixed, but in a CircuitHistory the "natural" node index is a pair (Hugr, Node), i.e. an index/ref to the correct hugr in the history, along with a node within it. Right now, I have "solved" this with the world's greatest hack, using the integer within Node to encode both a hugr index and the node index. This will overflow at 2^16 which we are bound to reach pretty quickly
  • Enumerating all nodes and counting them requires traversing the hugr, so this is a slow operation. Same with edge_count

There are still some minor TODOs, before this is mergeable (if we wish to merge it)

  • finish writing the history::test_history test
  • generalise apply_rewrite to CircuitHistory

@lmondada lmondada requested a review from a team as a code owner February 18, 2025 19:18
@lmondada lmondada requested review from ss2165 and removed request for a team February 18, 2025 19:18
@lmondada lmondada marked this pull request as draft February 18, 2025 19:18
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.51%. Comparing base (6bf8e4d) to head (8478612).
Report is 9 commits behind head on feat/circdiff.

Additional details and impacted files
@@                Coverage Diff                @@
##           feat/circdiff     #778      +/-   ##
=================================================
+ Coverage          82.48%   82.51%   +0.02%     
=================================================
  Files                 65       65              
  Lines               8178     8160      -18     
  Branches            7922     7904      -18     
=================================================
- Hits                6746     6733      -13     
  Misses              1012     1012              
+ Partials             420      415       -5     
Flag Coverage Δ
python ∅ <ø> (∅)

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ss2165
Copy link
Member

ss2165 commented Feb 24, 2025

This is really cool.

I haven't looked at the code in detail but I will comment on the main question.

I think it is worth having a read only and writable traits on hugr-like structs. This history object is one such struct. Our best candidate for that trait is currently HugrView. I think it falls short of that requirement by depending on HugrInternals, which is a trait which only makes sense when backed by one Hugr.

Ideally I think we should break that dependancy, but I'm not sure how viable that breaking change is. @aborgna-q may be better placed to comment on that.

@lmondada
Copy link
Contributor Author

This is being moved to hugr, see CQCL/hugr#2080

@lmondada lmondada closed this Apr 15, 2025
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.

2 participants