Skip to content
Merged
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
11 changes: 5 additions & 6 deletions scripts/profiling/aggregator/mock_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def write_template(
) -> Path:
"""
Write one full search-output directory via a test-mode bypass fit and return the
leaf directory (the one containing the `metadata` file).
leaf directory (the one containing the `files/search.json` that
`Aggregator.from_directory` discovers results by).
"""
template_prefix = f"_template/g{n_gaussians}_s{n_samples}"

Expand All @@ -92,8 +93,8 @@ def write_template(
model = model_from(n_gaussians)
analysis = af.ex.Analysis(data=np.ones(10), noise_map=np.ones(10))

# A stale template would append duplicate metadata lines (the file is opened in
# append mode), so remove any previous template for this config first.
# A stale template from an earlier configuration would be resumed rather than
# rewritten by the fit below, so remove any previous template for this config first.
for candidate in (
root / "test_mode" / Path(template_prefix),
root / Path(template_prefix),
Expand Down Expand Up @@ -167,7 +168,7 @@ def stamp_results(
):
"""
Copy the template `n_results` times under `results_root`, giving each copy a unique
`dataset_name` metadata entry and a unique `unique_tag` in its search.json.
`unique_tag` in its `files/search.json`.

The unique_tag matters for the sqlite database: fits are keyed by the identifier
hashed from (search, model, unique_tag), so identical copies would collapse to a
Expand All @@ -180,8 +181,6 @@ def stamp_results(
dataset_name = f"dataset_{i:04d}"
destination = results_root / dataset_name / "fit"
shutil.copytree(template_leaf, destination)
with open(destination / "metadata", "a") as f:
f.write(f"\ndataset_name={dataset_name}")
search_dict["arguments"]["unique_tag"] = dataset_name
(destination / "files" / "search.json").write_text(json.dumps(search_dict))
if zip_results:
Expand Down
10 changes: 5 additions & 5 deletions scripts/profiling/aggregator/profile_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- `values_samples_summary`: `values("samples_summary")` — the lightweight summary path.
- `values_model`: `values("model")`.
- `values_samples`: `values("samples")` — full `samples.csv` parse per result.
- `query_dataset_name`: a metadata predicate query.
- `query_unique_tag`: a `unique_tag` predicate query.
- `aggregate_csv`: `af.AggregateCSV` catalogue build (the csv_make workflow pattern).

Run from the `autofit_workspace_test` root, e.g.:
Expand Down Expand Up @@ -155,8 +155,8 @@ def fresh_agg():
timings["values_samples"] = timed(lambda: deque(agg.values("samples"), maxlen=0))

agg = fresh_agg()
timings["query_dataset_name"] = timed(
lambda: agg.query(agg.dataset_name == "dataset_0000")
timings["query_unique_tag"] = timed(
lambda: agg.query(agg.unique_tag == "dataset_0000")
)

agg = fresh_agg()
Expand All @@ -175,7 +175,7 @@ def aggregate_images():
agg_images = af.AggregateImages(agg)
agg_images.output_to_folder(
results_root.parent / "png",
name="dataset_name",
name="unique_tag",
subplots=[
SubplotFit.Data,
SubplotFit.ModelData,
Expand All @@ -192,7 +192,7 @@ def aggregate_fits():
agg_fits = af.AggregateFITS(agg)
agg_fits.output_to_folder(
results_root.parent / "fits",
name="dataset_name",
name="unique_tag",
hdus=[FITSFit.ModelData, FITSFit.ResidualMap],
)

Expand Down
2 changes: 1 addition & 1 deletion scripts/profiling/aggregator/profile_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

- `generate`: building the mock results (context, not a database cost).
- `database_build`: `from_database` + `add_directory` + commit on a fresh sqlite file.
- `database_query_unique_tag`: one indexed metadata query.
- `database_query_unique_tag`: one indexed `unique_tag` query.
- `database_values_samples`: `values("samples")` on a capped slice.
- `directory_from_directory` / `directory_values_samples`: the directory Aggregator on
the same results, same cap, for side-by-side comparison.
Expand Down
Loading