-
Notifications
You must be signed in to change notification settings - Fork 7
refactor!: More flexible pytket encoding #849
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
base: main
Are you sure you want to change the base?
Conversation
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary
|
a260ac4
to
f4ac585
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #849 +/- ##
==========================================
- Coverage 82.54% 80.70% -1.84%
==========================================
Files 72 81 +9
Lines 8827 9698 +871
Branches 8555 9426 +871
==========================================
+ Hits 7286 7827 +541
- Misses 1098 1393 +295
- Partials 443 478 +35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The blackbox encoding path is missing some test coverage. |
&self, | ||
typ: &hugr::types::CustomType, | ||
) -> Result<Option<RegisterCount>, Tk1ConvertError<<H>::Node>> { | ||
match typ.name().as_str() { |
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.
Should we be converting bools to bits as well?
tket2/src/serialize/pytket/tests.rs
Outdated
.iter() | ||
.map(|c| serde_json::to_string(c).unwrap()) | ||
.collect(); | ||
for b in &b.commands { |
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.
Shouldn't we be iterating over a.commands
here?
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.
Good catch -.-'
We actually cannot compare commands directly, since the arguments names may change depending on the encoding toposort.
I added a partial comparison instead.
/// | ||
/// ## Arguments | ||
/// | ||
/// - `node`: The HUGR for which to emit the command. Qubits and bits are |
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.
/// - `node`: The HUGR for which to emit the command. Qubits and bits are | |
/// - `node`: The HUGR node for which to emit the command. Qubits and bits are |
?
} | ||
if out_params.len() != total_out_count.params { | ||
return Err(Tk1ConvertError::custom(format!( | ||
"Not enough parameters in the input values for a {}. Expected {} but got {}.", |
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.
Could it be too many?
/// | ||
/// - `node`: The node to register the outputs for. | ||
/// - `circ`: The circuit containing the node. | ||
/// - `qubit_values`: An iterator of existing qubit ids to re-use for the output. |
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.
/// - `qubit_values`: An iterator of existing qubit ids to re-use for the output. | |
/// - `qubits`: An iterator of existing qubit ids to re-use for the output. |
// Check that we got the expected number of outputs. | ||
if out_params.len() != total_out_count.params { | ||
return Err(Tk1ConvertError::custom(format!( | ||
"Not enough parameters in the input values for a {}. Expected {} but got {}.", |
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.
Could it be too many?
}; | ||
// Update the values in the node's outputs. | ||
// | ||
// We preserve the order of linear values in thpe input |
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.
// We preserve the order of linear values in thpe input | |
// We preserve the order of linear values in the input |
Co-authored-by: Alec Edgington <[email protected]>
This PR rewrites the pytket encoding framework for hugr programs, and serves as a base for PRs to come.
Main changes from the existing implementation:
Extensions can define their own type, operation, and constant translations and register them at runtime.
This is done by registering
impl PytketEmitter
objects, that lets us emit arbitrary pytket commands for a hugr operation.See tket2/src/serialize/pytket/extension/ for how it's done.
Hugr
)Circuits that could already be encoded produce the same pytket circuit (up to register reorderings) after this refactor.
Previously unsupported circuits will now be encoded using black box barriers, but we do not include decoding support here.
Not in this PR:
-hseries
ops.BREAKING CHANGE: Removed some unused variants from
TK1ConvertError
andOpConvertError
.