Skip to content

refactor: ReplaceTypes linearization interface #2668

@acl-cqc

Description

@acl-cqc

Since #2435 we have developed several places where we jump through hoops to construct an invalid hugr before handing it over for linearization. The execution test for #2666 also faced similar problems.

There are at least a couple of options:

  • Rollback feat: ReplaceTypes allows linearizing inside Op replacements #2435, and go down the route of passing an &ReplaceTypes to all the callbacks instead. This might seem a more sensible API than ReplacementOptions, but still raises the question of how awkward it is to make the invalid hugr (e.g. using a builder) before giving it to that ReplaceTypes. Moreover it doesn't really help with the execution test.
  • Add a "linearizer" extension in hugr-passes, with a drop op (perhaps also copy) - this can replace the existing one in guppy/tket2. Then we'd need a ReplacementOptions that runs the ReplaceTypes on the Hugr (NodeTemplate) returned by the callback (i.e. containing that drop op) - feat: ReplaceTypes: recurse on replacements, much deprecation #2442 is aimed at doing this part. Ideally that option might even become the default ReplacementOptions (in time, that's a behaviour-breaking change); and we'd like the rule for lowering drop (using ReplacementOptions::with_linearization on an invalid hugr...thankfully we'd only need this in one place) to be included in ReplaceTypes::default() or maybe some ReplaceTypes::new_with_drop()

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions