Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Task.read interprets data incorrectly for short reads

オープン
#528 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
api, testing-qa

調査の方向性

nidaqmx.Task.read と tests/component/test_task_read_ai.py に記載されたテストから始め、特にマルチチャンネルの有限取得で短い読み取りを行うケースを確認してください。samples_to_acquire を 5、samples_to_read を 10 に設定して失敗を再現し、返された 2D データに各チャンネルの有効なサンプルが、値を上書きされることなく含まれていることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

When DAQmxReadAnalogF64 with DAQmx_Val_GroupByChannel returns fewer samples than requested, it squashes the valid samples together at the beginning of the buffer. The way that nidaqmx.Task.read handles short reads doesn't take this into account, so it may return samples that have been overwritten.

Test case (from tests/component/test_task_read_ai.py, under development):

def test___analog_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated(
    ai_multi_channel_task: nidaqmx.Task,
) -> None:
    samples_to_acquire = 5
    ai_multi_channel_task.timing.cfg_samp_clk_timing(rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=samples_to_acquire)
    num_channels = ai_multi_channel_task.number_of_channels
    samples_to_read = 10

    data = ai_multi_channel_task.read(samples_to_read)

    expected = [
        [_get_voltage_offset_for_chan(chan_index) for _ in range(samples_to_acquire)]
        for chan_index in range(num_channels)
    ]
    _assert_equal_2d(data, expected, abs=VOLTAGE_EPSILON)

Result (lib and grpc fail the same way, because the underlying interpreters have consistent behavior here):

_ test___analog_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated[library_init_kwargs] _

ai_multi_channel_task = Task(name=_unnamedTask<0>)

    def test___analog_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated(
        ai_multi_channel_task: nidaqmx.Task,
    ) -> None:
        samples_to_acquire = 5
        ai_multi_channel_task.timing.cfg_samp_clk_timing(rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=samples_to_acquire)
        num_channels = ai_multi_channel_task.number_of_channels
        samples_to_read = 10

        data = ai_multi_channel_task.read(samples_to_read)

        expected = [
            [_get_voltage_offset_for_chan(chan_index) for _ in range(samples_to_acquire)]
            for chan_index in range(num_channels)
        ]
>       _assert_equal_2d(data, expected, abs=VOLTAGE_EPSILON)

tests\component\test_task_read_ai.py:144:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

data = [[1.000091555528428, 1.000396740623188, 1.000396740623188, 0.999786370433668, 0.999786370433668], [3.000274666585284, ...4, 2.999969481490524], [3.000274666585284, 3.000579851680044, 3.000579851680044, 2.999969481490524, 2.999969481490524]]
expected = [[1.0, 1.0, 1.0, 1.0, 1.0], [2.0, 2.0, 2.0, 2.0, 2.0], [3.0, 3.0, 3.0, 3.0, 3.0]], abs = 0.001

    def _assert_equal_2d(data: List[List[float]], expected: List[List[float]], abs: float) -> None:
        # pytest.approx() does not support nested data structures.
        assert len(data) == len(expected)
        for i in range(len(data)):
>           assert data[i] == pytest.approx(expected[i], abs=abs)
E           assert [3.000274666585284, 3.000579851680044, 3.000579851680044, 2.999969481490524, 2.999969481490524] == approx([2.0 ± 1.0e-03, 2.0 ± 1.0e-03, 2.0 ± 1.0e-03, 2.0 ± 1.0e-03, 2.0 ± 1.0e-03])
E
E             comparison failed. Mismatched elements: 5 / 5:
E             Max absolute difference: 1.000579851680044
E             Max relative difference: 0.3334621643612693
E             Index | Obtained          | Expected
E             0     | 3.000274666585284 | 2.0 ± 1.0e-03
E             1     | 3.000579851680044 | 2.0 ± 1.0e-03
E             2     | 3.000579851680044 | 2.0 ± 1.0e-03
E             3     | 2.999969481490524 | 2.0 ± 1.0e-03
E             4     | 2.999969481490524 | 2.0 ± 1.0e-03

tests\component\test_task_read_ai.py:151: AssertionError

NI IO Trace shows:
image
image
image
image
image

The original array was
[1,1,1,1,1,0,0,0,0,0,2,2,2,2,2,0,0,0,0,0,3,3,3,3,3,0,0,0,0,0]
then it was squashed to
[1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x]
When this happened, the old 2s were overwritten with 3s.

This test case passes if you increase the number of samples to acquire because a larger read buffer prevents the old/new sample positions from overlapping.

主要言語
Python
スター
590
フォーク
199
平均マージ
1日 18時間
マージ済み PR(30日)
12

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ni/nidaqmx-python のほかの issue

ni/nidaqmx-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。