-
Notifications
You must be signed in to change notification settings - Fork 3
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
[QHC-833] Improving digital Transpilation #862
base: main
Are you sure you want to change the base?
Conversation
AI AnalysisReview:The changes in
|
optimization
word use in the transpilationoptimization
word use in the transpilation
optimization
word use in the transpilationTranspilation
Transpilation
Transpilation
Transpilation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #862 +/- ##
=======================================
Coverage 96.77% 96.78%
=======================================
Files 221 221
Lines 7756 7765 +9
=======================================
+ Hits 7506 7515 +9
Misses 250 250
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
…n compile and execute
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.
Nice job! Left some comments.
router: Router | type[Router] | tuple[type[Router], dict] | None = None, | ||
routing_iterations: int = 10, | ||
optimize: bool = True, | ||
program: Circuit | list[Circuit], runcard: str | dict, nshots: int = 1, transpile_config: dict = {} |
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 don't like replacing the parameters with a generic dictionary. Now, it is not clear what the dictionary should contain, what are the default values, there is no autocomplete etc.
In general, having all options as separate parameters is preferred.
If we really do need to use a single parameter, we should use a NamedDict or a new class.
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.
Also, default parameter values should not be mutable: https://docs.astral.sh/ruff/rules/mutable-argument-default/
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.
Also, default parameter values should not be mutable: https://docs.astral.sh/ruff/rules/mutable-argument-default/
Damn, true... I guess I'll have to set it back to None
then... started like that, but that made the code much uglier, with more checks, that complicated it... 😅. But definitely can go back to it, makes sense 👌
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 don't like replacing the parameters with a generic dictionary. Now, it is not clear what the dictionary should contain, what are the default values, there is no autocomplete etc.
In general, having all options as separate parameters is preferred.
If we really do need to use a single parameter, we should use a NamedDict or a new class.
Yeah I didn't like it either, but it was so many parameters, which might keep growing..., all of them related to the same thing, that in the end discussing it with @visagim we thought, it didn't make sense to keep the params separated, mixing with the other compile
/execute
parameters, when they clearly are more "modular" 😓. (That's also why I only did it for compile
/execute
's, but not for the transpile
methods down the line)
I also tried first to do a default class, but what I didn;t like about it, is the user having to import and initialize a random class, from a file in qililab
, dunno how intuitive that would be 😅. But its true that at least you would then have initialization.
Dunno I'm not 100% convinced what is better, I can try to generate the three examples:
- Keep params separated
- Ganeric kwargs
- Specific qililab dataclass
and ask again in a Code Discussion/daily, where everybody can see it and decide 👍 :
@@ -70,6 +70,7 @@ def __init__( | |||
# 3) Layout stage, where the initial_layout will be created. | |||
|
|||
def route(self, circuit: Circuit, iterations: int = 10) -> tuple[Circuit, dict[str, int]]: | |||
# Docstring related to the public method: :meth:`.CircuitTranspiler.route_circuit()`. Change it there 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.
Is this comment needed 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.
Yeah, good point... I actually have a problem here, which I wanted to ask about:
If you see, Inside the Transpiler
we have basically methods duplicated from the Optimizer
..., since we removed the handling of multiple circuits at the same time.. One option would be to remove such duplication, but at the same time that duplications serves as a kind of interface to add more functionality, and shows the user which functions can be called from the transpiler directly, so its not super bad...
Of course this makes that the docstrings are duplicated, and that is more problematic, since we wouldn't; want our devs, only updating the Optimizer
docstrings, but not the Transpiler
's which are more public. So the options we have are:
- Delete the duplication in some way (I think this will complicate how we show public method to the user...)
- Add this silly comment for devs to notice, that they need to change the public documentation always
- Maybe just delete the docstring from the not public methods? So there is no mistake by the devs? And they know to go and search elsewhere, which docstring to change 🤔...
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'll think more about it the next days, and ask the group with a clearer head...
But such problem make me notice there is a structural code problem from base with having this duplication, which maybe should be addressed more deeply... But 😬 ...
TODOs for this PR:
(each of the next points is pretty big deal, so check them all please 🙌🙃)
optimize
flag, for actual optional optimizations (& Improveoptimize
word use in methods names)Transpilation
/execute
/compile
only for single circuits (unify code standard acrossqililab
)Transpilation
efficient, by not constructing theCircuit
class so many times, between methodskwargs
instead of so many args inplatform
/qililab
'sexecute(...)
execute()
's, and moving it to a new section.You will see two empty methods, in this next PR I will fill them:
bunch_drag_gates(...)
,delete_gates_with_no_amplitude(...)
The documentation after this PR looks like:
For the
platform.execute()
:For the module about
Transpilation
:For the
Transpiler.transpile_circuit()
: