Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions src/explanation/computation-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,11 @@ class SignalAverage(dj.Computed):
avg_signal : float64
"""

def make_fetch(self, key):
"""Step 1: Fetch input data (outside transaction)"""
def make_fetch(self, key, **kwargs):
"""Step 1: Fetch input data (outside transaction).

kwargs are passed from populate(make_kwargs={...}).
"""
raw_signal = (RawSignal & key).fetch1("signal")
return (raw_signal,)

Expand Down
7 changes: 5 additions & 2 deletions src/how-to/run-computations.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@ class LongComputation(dj.Computed):
result : float64
"""

def make_fetch(self, key):
"""Fetch input data (outside transaction)"""
def make_fetch(self, key, **kwargs):
"""Fetch input data (outside transaction).

kwargs are passed from populate(make_kwargs={...}).
"""
data = (RawData & key).fetch1('data')
return (data,)

Expand Down
20 changes: 16 additions & 4 deletions src/reference/specs/autopopulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,11 @@ class HeavyComputation(dj.Computed):
result : <blob>
"""

def make_fetch(self, key):
"""Fetch all required data (runs in transaction)."""
def make_fetch(self, key, **kwargs):
"""Fetch all required data (runs in transaction).

kwargs are passed from populate(make_kwargs={...}).
"""
return (Recording & key).fetch1('raw_data')

def make_compute(self, key, data):
Expand Down Expand Up @@ -393,6 +396,15 @@ class ConfigurableAnalysis(dj.Computed):
ConfigurableAnalysis.populate(make_kwargs={'threshold': 0.8})
```

**Tripartite pattern:** When using the method-based tripartite pattern, `make_kwargs` are passed to `make_fetch()`:

```python
def make_fetch(self, key, verbose=False, **kwargs):
if verbose:
print(f"Fetching {key}")
return (Source & key).fetch1('data')
```

**Anti-pattern warning:** Passing arguments that affect the computed result breaks reproducibility—all inputs should come from `fetch` calls inside `make()`. If a parameter affects results, it should be stored in a lookup table and referenced via foreign key.

**Acceptable use:** Directives that don't affect results, such as:
Expand Down Expand Up @@ -973,8 +985,8 @@ def make(self, key):
yield # Re-acquire transaction
self.insert1({**key, 'result': result})

# Tripartite (methods)
def make_fetch(self, key): return data
# Tripartite (methods) - kwargs passed to make_fetch
def make_fetch(self, key, **kwargs): return data
def make_compute(self, key, data): return result
def make_insert(self, key, result): self.insert1(...)
```