Study¶
Multi-phase study orchestration.
trade_study.Phase(name, grid, filter_fn=None, n_trials=100, world=None, scorer=None)
dataclass
¶
A single phase in a multi-phase study.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Phase identifier (e.g. "discovery", "refinement"). |
grid |
list[dict[str, Any]] | str | GridCallable
|
Explicit config list, |
filter_fn |
Callable[[ResultsTable, list[Observable]], NDArray[intp]] | None
|
Optional callable that takes a ResultsTable and returns indices of configs to pass to the next phase. If None, phase is terminal. |
n_trials |
int
|
For adaptive mode, number of optuna trials. |
world |
Simulator | None
|
Optional phase-level simulator override. When set, this
phase uses world instead of the |
scorer |
Scorer | None
|
Optional phase-level scorer override. When set, this
phase uses scorer instead of the |
trade_study.Study(world, scorer, observables, phases, annotations=list(), factors=list())
dataclass
¶
Multi-phase model criticism study.
Attributes:
| Name | Type | Description |
|---|---|---|
world |
Simulator
|
Simulator generating (truth, observations). |
scorer |
Scorer
|
Scorer evaluating observables against truth. |
observables |
list[Observable]
|
Observable definitions. |
phases |
list[Phase]
|
Ordered list of study phases. |
annotations |
list[Annotation]
|
External information (costs, constraints). |
factors |
list[Any]
|
Factor definitions (needed for adaptive mode). |
run(*, n_jobs=1, callback=None)
¶
Execute all phases sequentially.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_jobs
|
int
|
Number of parallel workers for grid phases. |
1
|
callback
|
ProgressCallback | None
|
Optional progress callback invoked after each trial
with |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a callable grid is used on the first phase (no previous results to pass). |
Source code in src/trade_study/study.py
results(phase)
¶
Get results for a specific phase.
Returns:
| Type | Description |
|---|---|
ResultsTable
|
ResultsTable for the given phase. |
front(phase)
¶
Get Pareto front indices for a phase.
Returns:
| Type | Description |
|---|---|
NDArray[intp]
|
Integer array of Pareto-optimal row indices. |
Source code in src/trade_study/study.py
front_hypervolume(phase, ref_point)
¶
Compute hypervolume of the Pareto front for a phase.
Returns:
| Type | Description |
|---|---|
float
|
Hypervolume value. |
Source code in src/trade_study/study.py
stack(phase, *, maximize=False)
¶
Compute score-based stacking weights for a phase.
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Array of stacking weights. |
Source code in src/trade_study/study.py
summary()
¶
Per-phase summary: n_trials, n_front, observable ranges.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dictionary mapping phase names to summary statistics. |
Source code in src/trade_study/study.py
trade_study.top_k_pareto_filter(k, objective_names=None)
¶
Create a filter that keeps the top-K configs by Pareto rank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Maximum number of configs to keep. |
required |
objective_names
|
list[str] | None
|
Subset of observables to use for ranking. If None, uses all observables. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[ResultsTable, list[Observable]], NDArray[intp]]
|
Filter function compatible with Phase.filter_fn. |
Source code in src/trade_study/study.py
trade_study.weighted_sum_filter(weights, k)
¶
Create a filter that keeps the top-K configs by weighted sum.
Scalarises multiple objectives into a single score via a weighted sum
and keeps the k best configs. Scores are min-max normalised
before weighting so that objectives on different scales are
comparable. MAXIMIZE objectives are negated before normalisation so
that lower normalised values are always better.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
dict[str, float]
|
Mapping from observable name to its scalarisation weight. Only the named observables are used; the rest are ignored. |
required |
k
|
int
|
Maximum number of configs to keep. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[ResultsTable, list[Observable]], NDArray[intp]]
|
Filter function compatible with |
Source code in src/trade_study/study.py
trade_study.feasibility_filter(constraints)
¶
Create a filter that keeps only designs satisfying all constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints
|
list[Constraint]
|
Constraint objects to evaluate against results. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[ResultsTable, list[Observable]], NDArray[intp]]
|
Filter function compatible with |