Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Track derivation inputs in the cache hash of unset parameters
A parameter that is also a computed property (bandwidth,
demodulation_frequency) was treated as its own only leaf, so its cache
hash covered only its unset value. In-place changes to the inputs it is
derived from, such as center_frequency[:] = 6e6, left the cached value
stale. When such a parameter is unset, include its dependencies as
leaves as well.
  • Loading branch information
tristan-deep committed Nov 4, 2026
commit 1f624f4e0c8c2736121745fdf323959ff72453ce
9 changes: 9 additions & 0 deletions tests/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,15 @@ def test_bandwidth_derived_from_probe():
assert "bandwidth" in Parameters(**scan_args).to_tensor(include=["bandwidth"])


def test_bandwidth_follows_in_place_changes():
"""In-place changes to center_frequency refresh the derived bandwidth."""
parameters = Parameters(center_frequency=np.full(3, 5e6), probe_bandwidth_percent=60.0)
assert parameters.bandwidth == pytest.approx(3e6)

parameters.center_frequency[:] = 6e6
assert parameters.bandwidth == pytest.approx(3.6e6)


def test_bandwidth_explicit_value_wins():
"""An explicit bandwidth overrides the derived one, and unsetting it falls back."""
parameters = Parameters(center_frequency=5e6, probe_bandwidth_percent=60.0, bandwidth=1e6)
Expand Down
14 changes: 13 additions & 1 deletion zea/internal/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,26 @@ def _find_leaf_params(self, name, seen=None):
"""Recursively find all leaf parameters that a property depends on.

If it is an optional dependency parameter, it will be included as a leaf. Not the ones it
depends on.
depends on, unless it is unset and derived from them instead.
"""
if seen is None:
seen = set()
if name in seen:
return set()
seen.add(name)

# An optional dependency parameter that is unset falls back to its dependencies, so
# those are leaves too (e.g. bandwidth derived from center_frequency).
if (
name in self.VALID_PARAMS
and self._params.get(name) is None
and self._is_property_with_dependencies(name)
):
leaves = {name}
for dep in self._get_dependencies(name):
leaves |= self._find_leaf_params(dep, seen) # union
return leaves

# If the name is already a leaf parameter, return it
if name in self._params or name in self.VALID_PARAMS:
return {name}
Expand Down
Loading