-
Notifications
You must be signed in to change notification settings - Fork 7
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: Add tket2.bool
extension
#823
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #823 +/- ##
==========================================
- Coverage 82.58% 82.46% -0.13%
==========================================
Files 65 66 +1
Lines 8097 8274 +177
Branches 7834 8005 +171
==========================================
+ Hits 6687 6823 +136
- Misses 1005 1044 +39
- Partials 405 407 +2
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:
|
tket2-hseries/src/extension/bool.rs
Outdated
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 should explain the reason why this exists in addition to sums.
Is this only meant as a guppy artifact? The documentation seems to imply so.
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.
Great, thank you! I thought we were going to add this to the tket2
crate rather than tket2-hseries
? I would put it next to rotation.
I don't think we should reference guppy in the definition because there's nothing guppy-specific here.
tket2-hseries/src/extension/bool.rs
Outdated
@@ -0,0 +1,384 @@ | |||
//! This module defines the Hugr extension used to represent bools in Guppy. |
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 module defines the Hugr extension used to represent bools in Guppy. | |
//! This module defines the Hugr extension used to represent bools as an opaque type. |
tket2-hseries/src/extension/bool.rs
Outdated
ext.add_type( | ||
BOOL_TYPE_NAME.to_owned(), | ||
vec![], | ||
"The Guppy bool type".into(), |
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.
"The Guppy bool type".into(), | |
"An opaque bool type".into(), |
tket2-hseries/src/extension/bool.rs
Outdated
) | ||
} | ||
|
||
/// Returns a `bool` [Type]. |
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.
/// Returns a `bool` [Type]. | |
/// Returns a `tket2.bool` [Type]. |
tket2-hseries/src/extension/bool.rs
Outdated
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Hash, serde::Serialize, serde::Deserialize)] | ||
/// Structure for holding constant bool values. |
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.
/// Structure for holding constant bool values. | |
/// Structure for holding constant `tket2.bool` values. |
tket2-hseries/src/extension/bool.rs
Outdated
pub fn value(&self) -> &bool { | ||
&self.0 | ||
} |
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.
pub fn value(&self) -> &bool { | |
&self.0 | |
} | |
pub fn value(&self) -> bool { | |
self.0 | |
} |
bool
impls Copy
, no point returnin a reference I don't think.
tket2-hseries/src/extension/bool.rs
Outdated
#[typetag::serde] | ||
impl CustomConst for ConstBool { | ||
fn name(&self) -> ValueName { | ||
format!("ConstBool({:?})", self.0).into() |
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.
format!("ConstBool({:?})", self.0).into() | |
format!("ConstBool({self.0})").into() |
Note that this removes the :?
, so we are using Display
over Debug
to convert to a string. Usually that's what you want.
tket2-hseries/src/extension/bool.rs
Outdated
#[non_exhaustive] | ||
/// Simple enum of "tket2.bool" operations. | ||
pub enum BoolOpDef { | ||
BoolToSum, |
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.
Usually we use snake case constructors for this, i.e. bool_to_sum
. because these are user-facing names
tket2-hseries/src/extension/bool.rs
Outdated
|
||
fn description(&self) -> String { | ||
match self { | ||
BoolOpDef::BoolToSum => "Convert a Guppy bool into a Hugr unit sum.".into(), |
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.
BoolOpDef::BoolToSum => "Convert a Guppy bool into a Hugr unit sum.".into(), | |
BoolOpDef::BoolToSum => "Convert a tket2.bool into a Hugr unit sum.".into(), |
And the same for below
tket2-hseries/src/extension/bool.rs
Outdated
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
/// Concrete instances of a "tket2.bool" operations. | ||
pub enum BoolOp { |
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.
There's no need for both BoolOp
and BoolOpDef
here, because these ops have no type parameters. See QSystemOp
for an example of this case(although it does not follow my advice above of snake_case_names! awkward)
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.
Thanks! You could improve your coverage by adding a test that exercises all of the eq/or/not etc ops
Closes #817, enables https://github.com/quantinuum-dev/hugrverse/issues/130