-
Notifications
You must be signed in to change notification settings - Fork 6
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: Split & reassemble circuit chunks #130
Conversation
TODO: reassemble them
I'll add some python bindings before marking this as ready. |
I'm not convinced by the python interface (see |
.ok() | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not unwrap directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the linked_ports
iterator does not implement debug, and exactly_one
's error uses it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes I recall using the same trick, might be worth putting a utility for this somewhere so we have a comment about this in one place
src/passes/chunks.rs
Outdated
|
||
/// Insert the chunk back into a circuit. | ||
/// | ||
/// Returns a map from the original input/output wires to the inserted [`IncomingPorts`]/[`OutgoingPorts`]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be useful to add a comment saying one "Wire" could actually be connected
to many inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a ChunkInsertResult
with better docs.
src/passes/chunks.rs
Outdated
for commands in &circ.commands().chunks(max_size) { | ||
chunks.push(Chunk::extract( | ||
circ, | ||
commands.map(|cmd| cmd.node()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nicer to move this map to the loop definition
circ.commands().map(|cmd| ...)
|
||
let builder = FunctionBuilder::new(name, signature).unwrap(); | ||
let inputs = builder.input_wires(); | ||
let mut reassembled = builder.finish_hugr_with_outputs(inputs, ®ISTRY).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave a comment/TODO here about updating the registry correctly as well
src/passes/chunks.rs
Outdated
.collect() | ||
} | ||
|
||
/// Returns clones of the split circuits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrect docstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
This is a pass utility to split circuits into chunks that can be independently optimized.
Closes #129