feat: include units for duration and angles#9
Conversation
Another change is that "duration" is now an optional field of `MOp`
|
The solution is a little different then what I was thinking. It looks like pure floats are kept as pure floats and assumed to be radians and you have the option to include a "pi" unit; while, for durations it looks like you always have to specify the unit. To be consistent between angles and durations, I was thinking more, if the user can choose to supply both angles and durations as purely floats and that the Model will recast it as [float, "rad"], [float, "s"], respectively. (That is, float == [float, "rad"], float == [float, "s"], respectively.) The user/generator of the JSON can also choose to be explicit with typing. Is that a pain, e.g., for validation? Or do you think there are other issues with that? I kind of like your solution actually. The only thing that causes me pause is the inconsistency (but maybe they don't have to be consistent). |
|
@qciaran I won't worry about consistency between angles and durations. For angles, as you argued, it makes sense to have a default as it's both obvious and widely accepted that without any units, angles are radians. For durations, however, it's quite perplexing to not see any units attached while reading a number. As a further improvement, I am considering the unit of angles to be mentioned only once in the For example, compare: QOp(metadata=None, qop='PhasedX', returns=None, args=[('q', 0)],
angles=[(0.5, 'pi'), (0.5, 'pi')]),vs QOp(metadata=None, qop='PhasedX', returns=None, args=[('q', 0)],
angles=[0.5, 0.5], angles_unit="pi"), |
|
Since radian are usually given as unitless, that is fine. However, I would go with |
|
Agree with everything, except forcing How about the following definition for angles? angles: tuple[list[float], Literal("rad", "pi")] | None = None |
|
Yeah, that works for me. |
Based on feedback from Ciarán on the PR
|
@qciaran ready for your review. Thanks! |
Another change is that "duration" is now an optional field of
MOpCloses #6