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: Ops require their own extensions #734

Closed
wants to merge 30 commits into from
Closed

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Dec 2, 2023

The "fix" here is about three lines in op_def.rs. The rest is basically just updating tests to reflect the extra extension requirements, although there is a two-line fix in infer.rs, see here. I've also done this as a followup to #733, it may be applicable without.

WIP: the fixes here to sibling_subgraph do not look great, I have to say. If we agree this PR is indeed the way forward then we should discuss with @lmondada what to do here.

The test updates are straightforward, but massive, and rather painful. I see at least three options:

  1. Accept this is necessary because of the requirement for lift nodes. But, we can make this a bit less painful in the builder - for example, we could add a lift helper to the builder which just takes wires, and calculates the necessary type-row for them. (Another possibility: with_extension_delta could have variants that take single Extensions rather than a set.)
  2. Live with it for the time being, but reprioritize higher finding an alternative to lift nodes. (Perhaps automatic/automagic lift node "insertion".)
  3. Decide this is too painful for the time being, so hold off merging this to ease other work for the moment (this PR basically makes every test harder to write), and design an alternative.

I guess I'm arguing against doing (1) temporarily and then dropping lift nodes (and removing all those utilities) in the future...

closes #388

while !new_variables.is_empty() {
new_variables = new_variables
.into_iter()
.filter(|m| seen.insert(*m))
.flat_map(|m| self.get_constraints(&m).unwrap())
.flat_map(|m| self.get_constraints(&m).unwrap_or(&constraints_for_solved))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAICS solved constraints get removed here:

hugr/src/extension/infer.rs

Lines 633 to 635 in 6959c89

to_delete.iter().for_each(|m| {
self.constraints.remove(m);
});

so we have to handle them somehow. However I haven't looked into this all that hard so may have missed something @croyzor ?

@@ -189,6 +193,25 @@ fn test_dataflow_ports_only() {
)
.unwrap();
dfg.add_other_wire(not.node(), call.node()).unwrap();

// As temporary workaround for https://github.com/CQCL/hugr/issues/695
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit nasty, but should be solved by the two issues linked in due course.

@acl-cqc acl-cqc force-pushed the fix/ops_require_ext branch from e7c2940 to 89cea89 Compare December 3, 2023 09:39
@@ -246,9 +246,6 @@ impl SignatureFunc {
};

let res = pf.instantiate(args, exts)?;
// TODO bring this assert back once resource inference is done?
// https://github.com/CQCL/hugr/issues/388
// debug_assert!(res.extension_reqs.contains(def.extension()));
Copy link
Contributor

Choose a reason for hiding this comment

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

The assert should stay in, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now the inner function, called by the outer which modifies the result to add the necessary extra Extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But, seems we can now just do it here. A lot has changed since this PR started!!

Base automatically changed from new/values_know_extensions to main December 12, 2023 13:03
@acl-cqc acl-cqc marked this pull request as ready for review December 12, 2023 14:32
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

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

Comparison is base (679eefc) 84.47% compared to head (22c4458) 84.61%.

Files Patch % Lines
src/hugr/rewrite/replace.rs 81.81% 0 Missing and 4 partials ⚠️
src/builder/dataflow.rs 92.50% 0 Missing and 3 partials ⚠️
src/hugr/views/sibling_subgraph.rs 94.11% 0 Missing and 3 partials ⚠️
src/builder/circuit.rs 92.30% 0 Missing and 2 partials ⚠️
src/hugr/views/descendants.rs 95.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #734      +/-   ##
==========================================
+ Coverage   84.47%   84.61%   +0.13%     
==========================================
  Files          67       67              
  Lines       13214    13374     +160     
  Branches    13214    13374     +160     
==========================================
+ Hits        11163    11316     +153     
  Misses       1270     1270              
- Partials      781      788       +7     

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

@acl-cqc
Copy link
Contributor Author

acl-cqc commented Jan 8, 2024

Discussion with @ss2165 on 5th Jan - agreed Lift nodes like this are too painful. Hoping to switch to a subset constraint (at validation time) - inference algorithm details TBC...

@ss2165 ss2165 removed their request for review January 11, 2024 09:17
@acl-cqc
Copy link
Contributor Author

acl-cqc commented Jun 28, 2024

Superceded by #1226

@acl-cqc acl-cqc closed this Jun 28, 2024
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.

Custom operations implicitly require their extension
2 participants