Task.read does not return short reads for multi-channel power
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 592
- Forks
- 199
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 10
Description
Task.read doesn't slice the array for multi-channel power reads.
Test case (from tests/component/test_task_read_ai.py, under development):
def test___power_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated(
pwr_multi_channel_task: nidaqmx.Task,
) -> None:
samples_to_acquire = 5
pwr_multi_channel_task.timing.cfg_samp_clk_timing(rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=samples_to_acquire)
num_channels = pwr_multi_channel_task.number_of_channels
samples_to_read = 10
data = pwr_multi_channel_task.read(samples_to_read)
_assert_equal_2d(
[[e.voltage for e in d] for d in data],
[
[_get_voltage_setpoint_for_chan(chan_index) for _ in range(samples_to_acquire)]
for chan_index in range(num_channels)
],
abs=POWER_EPSILON,
)
_assert_equal_2d(
[[e.current for e in d] for d in data],
[
[_get_current_setpoint_for_chan(chan_index) for _ in range(samples_to_acquire)]
for chan_index in range(num_channels)
],
abs=POWER_EPSILON,
)
Result:
_ test___power_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated[library_init_kwargs] _
pwr_multi_channel_task = Task(name=_unnamedTask<F>)
def test___power_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated(
pwr_multi_channel_task: nidaqmx.Task,
) -> None:
samples_to_acquire = 5
pwr_multi_channel_task.timing.cfg_samp_clk_timing(rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=samples_to_acquire)
num_channels = pwr_multi_channel_task.number_of_channels
samples_to_read = 10
data = pwr_multi_channel_task.read(samples_to_read)
> _assert_equal_2d(
[[e.voltage for e in d] for d in data],
[
[_get_voltage_setpoint_for_chan(chan_index) for _ in range(samples_to_acquire)]
for chan_index in range(num_channels)
],
abs=POWER_EPSILON,
)
tests\component\test_task_read_ai.py:317:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
data = [[1.0, 1.0, 1.0, 1.0, 1.0, 2.0, ...], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ...]]
expected = [[1.0, 1.0, 1.0, 1.0, 1.0], [2.0, 2.0, 2.0, 2.0, 2.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 [1.0, 1.0, 1....1.0, 2.0, ...] == approx([1.0 ±....0 ± 1.0e-03])
E
E Impossible to compare lists with different sizes.
E Lengths: 5 and 10
tests\component\test_task_read_ai.py:152: AssertionError
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the failing case in tests/component/test_task_read_ai.py and trace the pwr_multi_channel_task.read(samples_to_read) call through Task.read. The fix is complete when the multi-channel finite power read returns five samples per channel when ten are requested, and the voltage and current assertions pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100