-
Notifications
You must be signed in to change notification settings - Fork 17
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
Q1ASM parse and generation #868
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #868 +/- ##
==========================================
+ Coverage 50.74% 54.36% +3.61%
==========================================
Files 63 65 +2
Lines 3019 3302 +283
==========================================
+ Hits 1532 1795 +263
- Misses 1487 1507 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
8d74b7f
to
6f4c84b
Compare
2f06159
to
7f6b648
Compare
This is the current state: [ins] In [1]: from qibolab._core.instruments.qblox.parse import parse
...: from pathlib import Path
...: from rich import print
...: basic = Path("tests/qblox/q1asm/basic.q1asm")
...: prog = parse(basic.read_text())
...: print(prog)
Program(
elements=[
'Basic example from docs\nhttps://qblox-qblox-instruments.readthedocs-hosted.com/en/main/tutorials/q1asm_tutorials/basic/baseband/basic_sequencing.html#Create-Q1ASM-program',
Line(Move(source='100', destination='R0'), comment='Loop iterator.'),
Line(Move(source='20', destination='R1'), comment='Initial wait period in ns.'),
Line(WaitSync(duration='4'), comment='Wait for sequencers to synchronize and then wait another 4 ns.'),
Line(SetMrk(mask='1'), label='loop', comment='Set marker output 1.'),
Line(Play(wave_0='0', wave_1='1', duration=4), comment='Play a gaussian and a block on output path 0 and 1 respectively and wait 4 ns.'),
Line(SetMrk(mask='0'), comment='Reset marker output 1.'),
Line(UpdParam(duration=18), comment='Update parameters and wait the remaining 18 ns of the waveforms.'),
Line(Wait(duration='R1'), comment='Wait period.'),
Line(Play(wave_0='1', wave_1='0', duration=22), comment='Play a block and a gaussian on output path 0 and 1 respectively and wait 22 ns.'),
Line(Wait(duration='1000'), comment='Wait a 1us in between iterations.'),
Line(Add(a='R1', b='20', destination='R1'), comment='Increase wait period by 20 ns.'),
Line(Loop(a='R0', address='@loop'), comment='Subtract one from loop iterator.'),
Line(Stop(), comment='Stop the sequence after the last iteration.')
]
)
[ins] In [2]: print(prog.asm(60))
# Basic example from docs
# https://qblox-qblox-instruments.readthedocs-hosted.com/en/main/tutorials/q1asm_tutorials/basic/baseband/basic_sequencing.html#Create-Q1ASM-program
move 100 R0 # Loop iterator.
move 20 R1 # Initial wait period in ns.
wait_sync 4 # Wait for sequencers to synchronize and
# then wait another 4 ns.
loop set_mrk 1 # Set marker output 1.
play 0 1 4 # Play a gaussian and a block on output
# path 0 and 1 respectively and wait 4
# ns.
set_mrk 0 # Reset marker output 1.
upd_param 18 # Update parameters and wait the
# remaining 18 ns of the waveforms.
wait R1 # Wait period.
play 1 0 22 # Play a block and a gaussian on output
# path 0 and 1 respectively and wait 22
# ns.
wait 1000 # Wait a 1us in between iterations.
add R1 20 R1 # Increase wait period by 20 ns.
loop R0 @loop # Subtract one from loop iterator.
stop # Stop the sequence after the last
# iteration.
[ins] In [3]: print(prog.asm(60, comments=False))
move 100 R0
move 20 R1
wait_sync 4
loop set_mrk 1
play 0 1 4
set_mrk 0
upd_param 18
wait R1
play 1 0 22
wait 1000
add R1 20 R1
loop R0 @loop
stop |
@stavros11 this module is missing documentation at all, and it is only tested globally in practical use cases, but there is no unit test at all. It is not my intention to fully skip these relevant parts, but the idea is that the assembly generation is fully internal, and not much useful as it is. In any case, I don't really want to merge, at least until I won't have something, even extremely tiny, built on top of this. |
Showcase once more the current results
[ins] In [1]: from pathlib import Path
[ins] In [2]: asm = Path("basic.q1asm").read_text()
[ins] In [3]: from qibolab._core.instruments.qblox.parse import parse
[ins] In [4]: print(parse(asm).asm())
# Basic example from docs
# https://qblox-qblox-instruments.readthedocs-hosted.com/en/main/tutorials/q1asm_tutorials/basic/baseband/basic_sequencing.html#Create-Q1ASM-program
move 100,R0 # Loop iterator.
move 20,R1 # Initial wait period in ns.
wait_sync 4 # Wait for sequencers to synchronize and then wait another 4 ns.
loop: set_mrk 1 # Set marker output 1.
play 0,1,4 # Play a gaussian and a block on output path 0 and 1 respectively and wait 4 ns.
set_mrk 0 # Reset marker output 1.
upd_param 18 # Update parameters and wait the remaining 18 ns of the waveforms.
wait R1 # Wait period.
play 1,0,22 # Play a block and a gaussian on output path 0 and 1 respectively and wait 22 ns.
wait 1000 # Wait a 1us in between iterations.
add R1,20,R1 # Increase wait period by 20 ns.
loop R0,@loop # Subtract one from loop iterator.
stop # Stop the sequence after the last iteration.
[ins] In [5]: print(parse(asm).asm(width=80))
# Basic example from docs
# https://qblox-qblox-instruments.readthedocs-hosted.com/en/main/tutorials/q1asm_tutorials/basic/baseband/basic_sequencing.html#Create-Q1ASM-program
move 100,R0 # Loop iterator.
move 20,R1 # Initial wait period in ns.
wait_sync 4 # Wait for sequencers to synchronize and then wait
# another 4 ns.
loop: set_mrk 1 # Set marker output 1.
play 0,1,4 # Play a gaussian and a block on output path 0 and 1
# respectively and wait 4 ns.
set_mrk 0 # Reset marker output 1.
upd_param 18 # Update parameters and wait the remaining 18 ns of the
# waveforms.
wait R1 # Wait period.
play 1,0,22 # Play a block and a gaussian on output path 0 and 1
# respectively and wait 22 ns.
wait 1000 # Wait a 1us in between iterations.
add R1,20,R1 # Increase wait period by 20 ns.
loop R0,@loop # Subtract one from loop iterator.
stop # Stop the sequence after the last iteration.
[ins] In [6]: print(parse(asm).asm(width=80, comments=False))
move 100,R0
move 20,R1
wait_sync 4
loop: set_mrk 1
play 0,1,4
set_mrk 0
upd_param 18
wait R1
play 1,0,22
wait 1000
add R1,20,R1
loop R0,@loop
stop
[ins] In [7]: print(parse(asm).asm(width=60))
# Basic example from docs
# https://qblox-qblox-instruments.readthedocs-hosted.com/en/main/tutorials/q1asm_tutorials/basic/baseband/basic_sequencing.html#Create-Q1ASM-program
move 100,R0 # Loop iterator.
move 20,R1 # Initial wait period in ns.
wait_sync 4 # Wait for sequencers to
# synchronize and then wait another
# 4 ns.
loop: set_mrk 1 # Set marker output 1.
play 0,1,4 # Play a gaussian and a block on
# output path 0 and 1 respectively
# and wait 4 ns.
set_mrk 0 # Reset marker output 1.
upd_param 18 # Update parameters and wait the
# remaining 18 ns of the waveforms.
wait R1 # Wait period.
play 1,0,22 # Play a block and a gaussian on
# output path 0 and 1 respectively
# and wait 22 ns.
wait 1000 # Wait a 1us in between iterations.
add R1,20,R1 # Increase wait period by 20 ns.
loop R0,@loop # Subtract one from loop iterator.
stop # Stop the sequence after the last
# iteration. |
8ac151f
to
f7a8883
Compare
f7a8883
to
442df19
Compare
Since it is a more accurate description: that is actually a reference to a label set somewhere else
There is no reason in saving the specific encodings of integers, or similar information, thus it can't be reproduced. Parsing will be a function, but not a bijective one, as there is no apparent advantage in making it such
Instead of spaces
More or less in the spirit of cross-validation: since the existing examples have been heavily used for development, let's check this is also working on something previously unobserved
Horrible patch. Some code should be refactored...
To adhere to linter's suggestions
d108ad5
to
1b0d8d2
Compare
Fix linter's warning
Attempting a complete parser and reconstructor for Q1ASM.
add Q1 execution timethe case of conditional jumps can't be fully worked out staticallyint
R
@