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: Split & reassemble circuit chunks #130

Merged
merged 12 commits into from
Sep 27, 2023
Merged

feat: Split & reassemble circuit chunks #130

merged 12 commits into from
Sep 27, 2023

Conversation

aborgna-q
Copy link
Collaborator

@aborgna-q aborgna-q commented Sep 22, 2023

This is a pass utility to split circuits into chunks that can be independently optimized.

Closes #129

@aborgna-q aborgna-q requested review from ss2165 and removed request for ss2165 September 27, 2023 11:00
@aborgna-q
Copy link
Collaborator Author

I'll add some python bindings before marking this as ready.

@aborgna-q aborgna-q marked this pull request as ready for review September 27, 2023 13:08
@aborgna-q
Copy link
Collaborator Author

aborgna-q commented Sep 27, 2023

I'm not convinced by the python interface (see test_bindings.py), but they work for now.

Comment on lines +77 to +78
.ok()
.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

why not unwrap directly?

Copy link
Collaborator Author

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.

Copy link
Member

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


/// Insert the chunk back into a circuit.
///
/// Returns a map from the original input/output wires to the inserted [`IncomingPorts`]/[`OutgoingPorts`].
Copy link
Member

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

Copy link
Collaborator Author

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.

for commands in &circ.commands().chunks(max_size) {
chunks.push(Chunk::extract(
circ,
commands.map(|cmd| cmd.node()),
Copy link
Member

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, &REGISTRY).unwrap();
Copy link
Member

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

.collect()
}

/// Returns clones of the split circuits.
Copy link
Member

Choose a reason for hiding this comment

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

incorrect docstring?

Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

👍

@aborgna-q aborgna-q merged commit d8fce77 into main Sep 27, 2023
7 checks passed
@aborgna-q aborgna-q deleted the feat/split-circ branch September 27, 2023 16:38
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.

Split and reassemble circuit chunks
2 participants