Skip to content

Commit 8a30ae1

Browse files
committed
Remove CSV writing from fit() to fix sequential crash recovery
1 parent ed22516 commit 8a30ae1

2 files changed

Lines changed: 1 addition & 59 deletions

File tree

src/easydiffraction/analysis/analysis.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-License-Identifier: BSD-3-Clause
33

44
from contextlib import suppress
5-
from pathlib import Path
65

76
import numpy as np
87
import pandas as pd
@@ -645,44 +644,6 @@ def fit(self, verbosity: str | None = None) -> None:
645644
expt_names = experiments.names
646645
num_expts = len(expt_names)
647646

648-
# CSV setup: write results if the project has been saved
649-
csv_path = None
650-
csv_header = None
651-
csv_free_names = None
652-
csv_diffrn_fields = None
653-
if self.project.info.path is not None:
654-
from easydiffraction.analysis.sequential import _META_COLUMNS # noqa: PLC0415
655-
from easydiffraction.analysis.sequential import _append_to_csv # noqa: PLC0415
656-
from easydiffraction.analysis.sequential import _write_csv_header # noqa: PLC0415
657-
658-
csv_path = Path(self.project.info.path) / 'analysis' / 'results.csv'
659-
csv_path.parent.mkdir(parents=True, exist_ok=True)
660-
661-
all_params = (
662-
self.project.structures.parameters + self.project.experiments.parameters
663-
)
664-
csv_free_names = [
665-
p.unique_name
666-
for p in all_params
667-
if isinstance(p, Parameter) and not p.constrained and p.free
668-
]
669-
670-
first_expt = list(experiments.values())[0]
671-
csv_diffrn_fields = []
672-
if hasattr(first_expt, 'diffrn'):
673-
csv_diffrn_fields = [
674-
p.name
675-
for p in first_expt.diffrn.parameters
676-
if hasattr(p, 'name') and p.name not in ('type',)
677-
]
678-
679-
csv_header = list(_META_COLUMNS)
680-
csv_header.extend(f'diffrn.{f}' for f in csv_diffrn_fields)
681-
for name in csv_free_names:
682-
csv_header.append(name)
683-
csv_header.append(f'{name}.uncertainty')
684-
_write_csv_header(csv_path, csv_header)
685-
686647
# Short mode: print header and create display handle once
687648
short_headers = ['experiment', 'χ²', 'iterations', 'status']
688649
short_alignments = ['left', 'right', 'right', 'center']
@@ -730,25 +691,6 @@ def fit(self, verbosity: str | None = None) -> None:
730691
self._parameter_snapshots[expt_name] = snapshot
731692
self.fit_results = results
732693

733-
# Append row to CSV
734-
if csv_path is not None:
735-
row = {
736-
'file_path': expt_name,
737-
'fit_success': results.success,
738-
'chi_squared': results.chi_square,
739-
'reduced_chi_squared': results.reduced_chi_square,
740-
'n_iterations': (self.fitter.minimizer.tracker.best_iteration or 0),
741-
}
742-
if hasattr(experiment, 'diffrn') and csv_diffrn_fields:
743-
for p in experiment.diffrn.parameters:
744-
if hasattr(p, 'name') and p.name not in ('type',):
745-
row[f'diffrn.{p.name}'] = p.value
746-
for uname in csv_free_names:
747-
if uname in snapshot:
748-
row[uname] = snapshot[uname]['value']
749-
row[f'{uname}.uncertainty'] = snapshot[uname]['uncertainty']
750-
_append_to_csv(csv_path, csv_header, [row])
751-
752694
# Short mode: append one summary row and update in-place
753695
if verb is VerbosityEnum.SHORT:
754696
chi2_str = (

src/easydiffraction/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _fetch_data_index() -> dict:
7373
_validate_url(index_url)
7474

7575
# macOS: sha256sum index.json
76-
index_hash = 'sha256:1032db0c04ef713c3f5209020a14b18dcdc3cfa4d995664ae5c9f5096f4508d4'
76+
index_hash = 'sha256:dfde966a084579c2103b0d35ed3e8688ddc6941335e251d3e1735a792ca06144'
7777
destination_dirname = 'easydiffraction'
7878
destination_fname = 'data-index.json'
7979
cache_dir = pooch.os_cache(destination_dirname)

0 commit comments

Comments
 (0)