Skip to content

Fix/experiment time range - #136

Closed
binary69 wants to merge 6 commits into
sensorium-competition:mainfrom
binary69:fix/experiment-time-range
Closed

Fix/experiment time range#136
binary69 wants to merge 6 commits into
sensorium-competition:mainfrom
binary69:fix/experiment-time-range

Conversation

@binary69

@binary69 binary69 commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator

Closes #134

Description
In _load_devices(), start_time and end_time were assigned with plain assignment inside a loop, so they reflected only the last loaded device instead of the global range across all devices.

Fix
Updated _load_devices() to use min/max to track the earliest start and latest end across all devices.

Test
Added tests/test_experiment.py 3 tests:

  • Single device: start/end matches that device's range
  • Two devices with different ranges: union is correct
  • Three devices with different ranges: union is correct

All 363 tests passing.

Copilot AI review requested due to automatic review settings March 16, 2026 09:49
@gitnotebooks

gitnotebooks Bot commented Mar 16, 2026

Copy link
Copy Markdown

Found 3 changed notebooks. Review the changes at https://app.gitnotebooks.com/sensorium-competition/experanto/pull/136

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix Experiment.start_time / Experiment.end_time so they reflect the global time range across all loaded devices (per the Experiment docstring), and adds regression tests for multi-device experiments.

Changes:

  • Add new tests/test_experiment.py covering single-, two-, and three-device time-range behavior.
  • Introduce a Ruff GitHub Actions workflow and add gsoc_env/ to .gitignore.
  • Clean up unused imports / minor string formatting across several modules and example notebooks.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/test_experiment.py Adds regression tests asserting experiment start/end reflect the global device range.
experanto/experiment.py Import cleanup only in the provided diff (core _load_devices() behavior not updated in current code).
experanto/utils.py Removes unused imports and unused locals in add_behavior_as_channels.
experanto/intervals.py Minor string formatting cleanup.
experanto/interpolators.py Removes unused import and simplifies error message strings.
experanto/datasets.py Import/unused-variable cleanup and removes a redundant override of DEFAULT_MODALITY_CONFIG.
experanto/dataloaders.py Import/unused-variable cleanup.
experanto/configs.py Import cleanup.
examples/sensorium/*.ipynb Removes unused imports in notebooks.
.gitignore Ignores gsoc_env/.
.github/workflows/ruff.yml Adds Ruff lint job (currently gated by an if condition).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_experiment.py
Comment on lines +117 to +128
experiment = Experiment(
root_folder=experiment_path,
modality_config=get_two_device_config(),
)

# Union: start = min(1.0, 0.0) = 0.0, end = max(8.0, 10.0) = 10.0
assert experiment.start_time == pytest.approx(
0.0
), f"Expected start_time=0.0, got {experiment.start_time}"
assert experiment.end_time == pytest.approx(
10.0
), f"Expected end_time=10.0, got {experiment.end_time}"
Comment thread tests/test_experiment.py
Comment on lines +11 to +56
EXPERIMENT_ROOT = Path("tests/experiment_data")


@contextmanager
def create_two_device_experiment(
device0_start=0.0,
device0_end=10.0,
device1_start=1.0,
device1_end=8.0,
sampling_rate=10.0,
):
"""Create a temporary experiment with two sequence devices with different time ranges."""
try:
for device_name, start, end in [
("device_0", device0_start, device0_end),
("device_1", device1_start, device1_end),
]:
device_root = EXPERIMENT_ROOT / device_name
(device_root / "meta").mkdir(parents=True, exist_ok=True)

n_samples = int((end - start) * sampling_rate) + 1
timestamps = np.linspace(start, end, n_samples)
data = np.random.rand(n_samples, 5)

np.save(device_root / "timestamps.npy", timestamps)
np.save(device_root / "data.npy", data)

meta = {
"start_time": start,
"end_time": end,
"modality": "sequence",
"sampling_rate": sampling_rate,
"phase_shift_per_signal": False,
"is_mem_mapped": False,
"n_signals": 5,
"n_timestamps": n_samples,
"dtype": "float64",
}
with open(device_root / "meta.yml", "w") as f:
yaml.safe_dump(meta, f)

yield EXPERIMENT_ROOT

finally:
shutil.rmtree(EXPERIMENT_ROOT)


jobs:
ruff:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
Comment thread experanto/experiment.py
Comment on lines 1 to 9
from __future__ import annotations

import logging
import re
import warnings
from collections.abc import Sequence
from pathlib import Path
from typing import Optional, Union
from typing import Union

import numpy as np
from hydra.utils import instantiate
@pollytur

Copy link
Copy Markdown
Contributor

please, re-submit a PR making changed from the current main only, not from your other branch

@pollytur pollytur closed this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Experiment.start_time and end_time reflect only the last loaded device, not the global range in experiment.py

3 participants