-
Notifications
You must be signed in to change notification settings - Fork 9
fix!: Fix rotation -> float param type conversion #1061
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
Conversation
@@ -217,7 +217,7 @@ impl PyPauliIter { | |||
// | |||
// TODO: These can no longer be constructed from Python. Since `hugr-rs 0.14` | |||
// we need an extension and `OpDef` to defines these. | |||
// If fixing this, make sure to fix `PyHugrType` too. |
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.
Dummy change so this gets a line in the tket-py changelog
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1061 +/- ##
==========================================
- Coverage 78.19% 78.13% -0.06%
==========================================
Files 102 102
Lines 12783 12886 +103
Branches 12504 12607 +103
==========================================
+ Hits 9996 10069 +73
- Misses 2130 2162 +32
+ Partials 657 655 -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:
|
Rule::multiply => FloatOps::fmul, | ||
Rule::divide => FloatOps::fdiv, | ||
Rule::power => FloatOps::fpow, | ||
Rule::add => RotationOp::radd.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.
wait why is it just addition that is mapping to rotation..?
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 that's the only arithmetic op in the rotation extension u.u
Using it instead of the float variant lets us avoid from/to conversions for most operations. It's equivalent.
95a71d4
to
620cea6
Compare
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary
|
tket-qsystem/src/pytket/qsystem.rs
Outdated
@@ -83,8 +84,23 @@ impl QSystemEmitter { | |||
} | |||
}; | |||
|
|||
// We have to convert the parameters expressions (in half-turns) to radians. |
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.
comment is wrong way round?
/// See [`PytketDecoderContext::load_parameter`] for more details. | ||
pub fn load_parameter_with_type(&mut self, param: &str, typ: ParameterType) -> LoadedParameter { | ||
self.wire_tracker | ||
.load_parameter(&mut self.builder, param, Some(typ)) |
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.
seems strange to pass the typ
to both load and with, but I guess it is optional in the first case
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.
As mentioned in the load_parameter
docs, that is a type hint that lets us decide for example between loading a rotation const or a float const. The output type is not guaranteed to have that type.
I guess it'd be less confusing if we change the hint for an assurance and do the with_type
internally. I'll make the change.
args: Vec<PytketParam<'a>>, | ||
/// The parameter types used for the inputs and outputs of this operation. |
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.
lets hope we don't run in to any that have mixed eh...
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 set of operations we translate is quite restricted, so hopefully this should be enough 🤞
Some(ParameterType::FloatHalfTurns) => { | ||
let value: Value = ConstF64::new(half_turns).into(); | ||
let wire = hugr.add_load_const(value); | ||
LoadedParameter::float_half_turns(wire) | ||
} | ||
_ => { | ||
let value: Value = ConstRotation::new(half_turns).unwrap().into(); | ||
let wire = hugr.add_load_const(value); | ||
LoadedParameter::rotation(wire) | ||
} |
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 still think a pytket expression tree should be loaded in to hugr in one go as just a float expression tree, and then the final root of the tree converted in to a Rotation. I.e. this second non-type hinted case need not exist? I realise that messes with the recursive loading architecture here but it is much cleaner and avoids confusing cases like this. We can leave this for a future refactor since I don't think it actually changes behaviour (other than maybe adding/removing some needless conversions back and forth)
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 guess we could change the SympyOp to return a float / add a new op to avoid breaking -exts
.
But input params will still be rotations, so we'd be adding unnecessary conversions.
And same for consts.
I realize adding RotationOp::to_halfturns
/from_halfturns
is not expensive, but neither is checking the type here ¯\(ツ)/¯
🤖 I have created a release *beep* *boop* --- ## [0.12.3](tket-py-v0.12.2...tket-py-v0.12.3) (2025-08-22) ### Features * Explicit exports for tket_exts ops and types ([#1046](#1046)) ([a32873e](a32873e)) ### Bug Fixes * Fix erroneous parameters being decoded from pytket for qsystem gates ([#1061](#1061)) ([cd42644](cd42644)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: Seyon Sivarajah <seyon.sivarajah@quantinuum.com> Co-authored-by: Seyon Sivarajah <seyon.sivarajah@cambridgequantum.com>
Fixes inconsistent encoding/decoding parameters. Now we keep them in half-turns most of the time, unless an specific operation requires them to be in radians.
ParameterType
used while decoding now has variantsRotation | FloatHalfTurns | FloatRadians
.Operation decoders must now specify which one they expect for their inputs.
FloatHalfTurns
, to avoid unnecessary conversions from/to radians.qsystem
ops must then add a/ pi
before emitting their command.BREAKING CHANGE: (pytket decoder) Renamed
LoadedParameterType
toParameterType
and changed its variants.BREAKING CHANGE: (pytket decoder) Made
LoadedParameter
attributes private, and modified its API to support the new type variants.BREAKING CHANGE: (pytket encoder) Changed
MakeOperationArgs
's parameter list to aCow
.This is not a breaking change for python;
BEGIN_COMMIT_OVERRIDE
fix: Fix erroneous parameters being decoded from pytket for qsystem gates (#1061)
END_COMMIT_OVERRIDE