Skip to content

[Bug]: Waveforms disagree on how a negative duration fails #18

Description

@fedonman

Bug Description

Every envelope() computes its sample count with a bare n_samples = int(duration / resolution) and hands it to numpy without checking that it is positive, and the eight waveforms that do this each inherit whatever numpy does next. Sech and Gaussian return an empty array, Ramp raises ValueError out of np.linspace, Square raises a different ValueError out of np.zeros. A swept duration variable can reach a negative value, so the same program fails three different ways depending on which waveform is playing, and none of the failures is a qprogram error type naming the duration. A shared sample-count helper that raises ValidationError on a negative duration would settle all of them at once.

Minimal Reproducible Example

from qprogram.waveforms import Ramp, Sech, Square

Sech(1.0, -10, 3).envelope()    # empty array
Square(1.0, -10).envelope()     # ValueError from np.zeros
Ramp(0.0, 1.0, -10).envelope()  # ValueError from np.linspace

Expected Behavior

One rule for every waveform, ideally a ValidationError naming the offending duration.

Actual Behavior

Sech  -> array([], dtype=float64)
Square -> ValueError: negative dimensions are not allowed
Ramp  -> ValueError: Number of samples, -10, must be non-negative.

System Information

qprogram 0.1.0
python   3.14.3 | Linux-7.0.0-30-generic-x86_64-with-glibc2.43
vendors  none

Metadata

Metadata

Assignees

No one assigned

    Labels

    waveformsTouches waveforms and the waveform library

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions