QuEraComputing / bloqade-python

QuEra's Neutral Atom SDK for Analog QPUs
https://bloqade.quera.com/
Other
55 stars 14 forks source link

tutorial 1 gives decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>] #879

Closed Roger-luo closed 9 months ago

Roger-luo commented 9 months ago

just run the tutorial one script (without emulation data file), and you will get the following

> python example-1-rabi.py
Traceback (most recent call last):
  File "/Users/roger/Code/slides/bloqade-slides/example-1-rabi.py", line 108, in <module>
    emu_batch = rabi_oscillation_job.braket.local_emulator().run(10000)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<@beartype(bloqade.ir.routine.braket.BraketLocalEmulatorRoutine.run) at 0x14c0b0c20>", line 126, in run
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/routine/braket.py", line 257, in run
    batch = self._compile(shots, args, name)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/routine/braket.py", line 213, in _compile
    validate_waveforms(level_couplings, final_circuit)
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/compiler/passes/hardware/define.py", line 159, in validate_waveforms
    ValidatePiecewiseLinearChannel(*channel).visit(circuit)
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/visitor.py", line 41, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/visitor.py", line 46, in generic_visit
    self.visit(value)
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/visitor.py", line 41, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/compiler/analysis/hardware/piecewise_linear.py", line 93, in visit_sequence_Sequence
    return self.visit(node.pulses[self.level_coupling])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/visitor.py", line 41, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/compiler/analysis/hardware/piecewise_linear.py", line 118, in visit_pulse_Pulse
    return self.visit(node.fields[self.field_name])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/visitor.py", line 41, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/compiler/analysis/hardware/piecewise_linear.py", line 123, in visit_field_Field
    self.visit(wf)
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/visitor.py", line 41, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/compiler/analysis/hardware/piecewise_linear.py", line 65, in visit_waveform_Append
    self.check_continuous(time, "Waveform", lhs, rhs)
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/compiler/analysis/hardware/piecewise_linear.py", line 25, in check_continuous
    diff = abs(lhs.eval_decimal(lhs.duration()) - rhs.eval_decimal(Decimal(0)))
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/roger/Code/slides/bloqade-slides/.venv/lib/python3.11/site-packages/bloqade/ir/control/waveform.py", line 289, in eval_decimal
    (stop_value - start_value) / self.duration(**kwargs)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
decimal.InvalidOperation: [<class 'decimal.DivisionUndefined'>]
Roger-luo commented 9 months ago

also can we have our CI actually executing the file without any cached data? e.g we can let this trigger by PR comments only

Roger-luo commented 9 months ago

the example is not runing because

run_times = np.linspace(0, 3, 101)

this assigns the first duration to be zero, which causing trouble for compile checks

weinbe58 commented 9 months ago

There must be a bug in the canonicalization pass which should have removed the segment with a duration = 0.

EDIT: Don't see any bugs, also there are tests to cover this so I am not entirely sure what is going on here.

weinbe58 commented 9 months ago

What version are you running? I can't reproduce this error.

weinbe58 commented 9 months ago

Docs finished building successfully: https://github.com/QuEraComputing/bloqade-python-examples/actions/runs/7598088111

Roger-luo commented 9 months ago

What version are you running? I can't reproduce this error.

lastest pypi version?

EDIT: Don't see any bugs, also there are tests to cover this so I am not entirely sure what is going on here.

even after removing the data file?