Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ec61bab
fix: compute Experiment start/end time as union across all devices
binary69 Mar 16, 2026
1008758
test: use pytest tmp_path for cleaner test isolation
binary69 Mar 16, 2026
118a928
style: auto-format with black and isort
invalid-email-address Mar 16, 2026
36e6707
fix: add None guard for dev.start_time and end_time in _load_devices
binary69 Mar 16, 2026
45c6881
test: separate data creation helpers into create_experiment.py
binary69 Mar 16, 2026
38153ad
style: auto-format with black and isort
invalid-email-address Mar 16, 2026
791bb98
fix: improve None handling with warning and add finite range validation
binary69 Mar 16, 2026
d6737de
style: auto-format with black and isort
invalid-email-address Mar 16, 2026
7c07754
fix for pull request finding
binary69 Mar 16, 2026
dbf1896
fix for pull request finding
binary69 Mar 16, 2026
55e8f2e
style: auto-format with black and isort
invalid-email-address Mar 16, 2026
a068290
style: reformat elif condition to Black-compliant style
binary69 Mar 16, 2026
ae606bd
style: auto-format with black and isort
invalid-email-address Mar 16, 2026
929c92d
fix: experiment time range validation and test refactor
binary69 Mar 17, 2026
a7edf85
fix: remove unused imports flagged by ruff
binary69 Mar 18, 2026
423f86f
style: auto-format with black and isort
invalid-email-address Mar 17, 2026
86dc0bc
fix: replace np.isinf with np.isfinite to catch NaN and -inf values
binary69 Mar 18, 2026
3f4aa6e
fix: make sampling_rates and offsets per-device lists in make_modalit…
binary69 Mar 18, 2026
2e3cddf
fix: expand test coverage with edge cases, parametrize invalid device…
binary69 Mar 18, 2026
3c2ccc3
style: auto-format with black and isort
invalid-email-address Mar 18, 2026
863e52c
fix: restore imports to match main branch
binary69 Mar 19, 2026
acbfd6c
style: auto-format with black and isort
invalid-email-address Mar 19, 2026
17f752e
merge: sync with upstream main and resolve experiment.py conflict
binary69 Mar 19, 2026
33828ea
merge: resolve experiment.py conflict keeping upstream main imports
binary69 Mar 19, 2026
63f7589
fix: use correct sampling_rate parameter and random values in union test
binary69 Mar 19, 2026
2488615
style: auto-format with black and isort
invalid-email-address Mar 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions experanto/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,26 @@ def _load_devices(self) -> None:
)

self.devices[d.name] = dev
Comment thread
binary69 marked this conversation as resolved.
Outdated
self.start_time = dev.start_time
self.end_time = dev.end_time
if dev.start_time is None or dev.end_time is None:
logger.warning(
"Device %s has undefined start_time or end_time and will be "
"excluded from the experiment-wide time range.",
d.name,
)
else:
self.start_time = min(self.start_time, dev.start_time)
self.end_time = max(self.end_time, dev.end_time)
Comment thread
binary69 marked this conversation as resolved.
Outdated
Comment thread
binary69 marked this conversation as resolved.
Comment thread
binary69 marked this conversation as resolved.
Comment thread
binary69 marked this conversation as resolved.
Outdated
Comment thread
binary69 marked this conversation as resolved.
logger.info("Parsing finished")
if not self.devices:
logger.warning(
"No devices were loaded. Please check your root folder %s",
self.root_folder,
)
elif not np.isfinite(self.start_time) and np.isfinite(self.end_time):
raise ValueError(
"Experiment time range could not be determined: at least one device "
"must define finite start_time and end_time."
)

Comment thread
binary69 marked this conversation as resolved.
Outdated
Comment thread
binary69 marked this conversation as resolved.
Outdated
@property
def device_names(self):
Expand Down
36 changes: 36 additions & 0 deletions tests/create_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import yaml


Comment thread
binary69 marked this conversation as resolved.
def make_sequence_device(root, name, start, end, sampling_rate=10.0):
"""Create a single sequence device folder under root."""
device_root = root / name
(device_root / "meta").mkdir(parents=True, exist_ok=True)
Comment thread
pollytur marked this conversation as resolved.
Outdated

n_samples = int((end - start) * sampling_rate) + 1
Comment thread
binary69 marked this conversation as resolved.
Outdated
timestamps = np.linspace(start, end, n_samples)
data = np.random.rand(n_samples, 5)
Comment thread
binary69 marked this conversation as resolved.
Outdated

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)


def make_modality_config(*device_names):
return {
name: {"interpolation": {"sampling_rate": 10.0, "offset": 0.0}}
Comment thread
binary69 marked this conversation as resolved.
Outdated
for name in device_names
}
56 changes: 56 additions & 0 deletions tests/test_experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pytest

from experanto.experiment import Experiment

from .create_experiment import make_modality_config, make_sequence_device


def test_experiment_start_end_time_reflects_union(tmp_path):
"""
Experiment.start_time and end_time should reflect the union of all
device time ranges — earliest start and latest end across all devices.
"""
Comment thread
binary69 marked this conversation as resolved.
Outdated
make_sequence_device(tmp_path, "device_0", start=1.0, end=8.0)
make_sequence_device(tmp_path, "device_1", start=0.0, end=10.0)

experiment = Experiment(
root_folder=tmp_path,
modality_config=make_modality_config("device_0", "device_1"),
)

# 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
pollytur marked this conversation as resolved.
Outdated

Comment thread
binary69 marked this conversation as resolved.

def test_experiment_single_device_time_range(tmp_path):
"""With a single device, start_time and end_time should match that device's range."""
make_sequence_device(tmp_path, "device_0", start=2.0, end=9.0)

experiment = Experiment(
root_folder=tmp_path,
modality_config=make_modality_config("device_0"),
)

assert experiment.start_time == pytest.approx(2.0)
assert experiment.end_time == pytest.approx(9.0)


def test_experiment_start_end_time_three_devices(tmp_path):
Comment thread
binary69 marked this conversation as resolved.
Outdated
"""With three devices, start_time and end_time should reflect the union of all three."""
make_sequence_device(tmp_path, "device_0", start=0.0, end=10.0)
make_sequence_device(tmp_path, "device_1", start=1.0, end=8.0)
make_sequence_device(tmp_path, "device_2", start=2.0, end=9.0)

experiment = Experiment(
root_folder=tmp_path,
modality_config=make_modality_config("device_0", "device_1", "device_2"),
)

# Union: start = min(0.0, 1.0, 2.0) = 0.0, end = max(10.0, 8.0, 9.0) = 10.0
assert experiment.start_time == pytest.approx(0.0)
assert experiment.end_time == pytest.approx(10.0)
Loading