Skip to content

Commit 4ef6443

Browse files
authored
Merge pull request #254 from ICAMS/fix_autodetect
Fix autodetect
2 parents 5369ff9 + ac26b0e commit 4ef6443

14 files changed

Lines changed: 756 additions & 4565 deletions

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.8.2
2+
current_version = 1.8.3
33
commit = True
44
tag = True
55

calphy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from calphy.alchemy import Alchemy
55
from calphy.routines import MeltingTemp
66

7-
__version__ = "1.8.2"
7+
__version__ = "1.8.3"
88

99
def addtest(a,b):
1010
return a+b

calphy/alchemy.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ def run_averaging(self):
117117
else:
118118
self.run_finite_pressure_equilibration(lmp)
119119

120-
# create the fluctuation monitor before the pressure-convergence cycle loop
121-
self._create_monitor("solid")
122-
123120
# this is when the averaging routine starts
124121
self.run_pressure_convergence(lmp)
125122

calphy/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ class SolidifiedError(CustomError):
3535
pass
3636

3737
class PhaseTransitionError(CustomError):
38-
"""Raised when the ts-sweep transition detector flags a phase transition."""
38+
"""Raised when the pre-flight temperature-range scan flags a phase transition."""
3939
pass
4040

calphy/input.py

Lines changed: 88 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from ase.io import read, write
5050
import shutil
5151

52-
__version__ = "1.8.2"
52+
__version__ = "1.8.3"
5353

5454

5555
def _check_equal(val):
@@ -248,33 +248,41 @@ class Queue(BaseModel, title="Options for configuring queue"):
248248
class Tolerance(BaseModel, title="Tolerance settings for convergence"):
249249
lattice_constant: Annotated[float, Field(default=0.0002, ge=0)]
250250
spring_constant: Annotated[float, Field(default=0.1, gt=0)]
251-
solid_fraction: Annotated[float, Field(default=0.7, ge=0)]
252-
liquid_fraction: Annotated[float, Field(default=0.05, ge=0)]
251+
# Structural phase-stability checks during equilibration are OFF by
252+
# default: solid_fraction=0 means the melt check (solid_fraction < this)
253+
# never fires, and liquid_fraction=1.0 means the solidify check
254+
# (solid_fraction > this) never fires. Set solid_fraction > 0 (e.g. 0.7)
255+
# to re-enable melt detection for a solid run, or liquid_fraction < 1
256+
# (e.g. 0.05) to re-enable solidification detection for a liquid run.
257+
solid_fraction: Annotated[float, Field(default=0.0, ge=0)]
258+
liquid_fraction: Annotated[float, Field(default=1.0, ge=0)]
253259
pressure: Annotated[float, Field(default=10.0, ge=0)]
254260

255261

256-
class PhaseTransitionDetection(BaseModel, title="Settings for fluctuation-based phase transition detection"):
262+
class PhaseTransitionDetection(BaseModel, title="Settings for the pre-flight temperature-range scan"):
257263
mode: Annotated[
258-
Literal["none", "warn", "recover", "stop"],
264+
Literal["none", "adapt", "warn", "stop"],
259265
Field(
260266
default="none",
261267
description=(
262-
"Controls what happens when a phase transition is detected "
263-
"during a reversible-scaling sweep.\n"
264-
" 'none' — detection is disabled; sweep always completes "
265-
"(default).\n"
266-
" 'warn' — detection runs and a warning is logged with the "
267-
"estimated transition temperature and triggering signals; "
268-
"response-function plots are generated; the sweep continues "
269-
"to completion uninterrupted. Use this to observe detection "
270-
"without changing the calculation outcome.\n"
271-
" 'recover' — truncate the forward sweep at the last clean "
272-
"block boundary, save a checkpoint, and continue with a "
273-
"backward sweep over the reduced range [T0, T_k]. A valid "
274-
"free-energy curve is produced for the single-phase region.\n"
275-
" 'stop' — raise PhaseTransitionError and abort. Use "
276-
"when you want to inspect the raw data before deciding how "
277-
"to proceed."
268+
"Controls the pre-flight temperature-range scan that runs "
269+
"before a reversible-scaling (ts) sweep. The scan performs a "
270+
"single fast real-thermostat temperature ramp (T0 -> Tf under "
271+
"NPT) and watches the fluctuation response functions for the "
272+
"onset of a phase transition.\n"
273+
" 'none' — the scan is disabled; the ts sweep runs over the "
274+
"requested [T0, Tf] range as-is (default).\n"
275+
" 'adapt' — if the scan detects a transition, reduce the upper "
276+
"temperature to the detected clean onset and run the ts sweep "
277+
"over [T0, T_clean] (keeping the same number of switching "
278+
"steps). If the scan is clean the range is unchanged.\n"
279+
" 'warn' — run the scan and log the detected clean range, but "
280+
"do NOT modify the calculation; the ts sweep runs over the full "
281+
"requested range. Use this to observe detection without "
282+
"changing the outcome.\n"
283+
" 'stop' — if a transition is detected, raise "
284+
"PhaseTransitionError reporting the clean range so you can "
285+
"re-submit with a corrected temperature range."
278286
),
279287
),
280288
]
@@ -312,29 +320,71 @@ class PhaseTransitionDetection(BaseModel, title="Settings for fluctuation-based
312320
default=4.0,
313321
gt=0,
314322
description=(
315-
"Walk-back threshold used to locate the onset temperature from a "
316-
"detected peak. Applied to all signals: variance-based signals "
317-
"(Cp, kappa_T, alpha_P) walk back to where the signal falls below "
318-
"baseline_median + onset_sigma * MAD; slope-break signals "
319-
"(H_break, V_break) walk back to where |z| falls below onset_sigma. "
320-
"Lower values give earlier (more conservative) onsets and therefore "
321-
"earlier recovery cuts; higher values place the onset closer to the "
322-
"unambiguous part of the peak. Default 4.0."
323+
"Walk-back threshold for the variance-based signals (Cp, "
324+
"kappa_T, alpha_P), whose rolling-window peak sits AT the "
325+
"transition. Their onset is walked back from the peak to where "
326+
"the signal falls below baseline_median + onset_sigma * MAD. "
327+
"The slope-break signals use onset_level instead. Default 4.0."
323328
),
324329
),
325330
]
326-
baseline_window: Annotated[int, Field(default=50, ge=5)]
327-
recent_window: Annotated[int, Field(default=50, ge=5)]
328-
min_samples_before_check: Annotated[int, Field(default=100, ge=10)]
329-
temperature_window: Annotated[
331+
onset_level: Annotated[
330332
float,
331333
Field(
332-
default=50.0,
333-
ge=0,
334+
default=1.5,
335+
gt=0,
336+
description=(
337+
"Low-sigma walk-back level for the slope-break signals (H_break, "
338+
"V_break), used to place the clean boundary at the FOOT of the "
339+
"transition — where the mean enthalpy/volume first starts leaving "
340+
"the single-phase equation of state — rather than at its collapse. "
341+
"This matters because a reversible-scaling sweep equilibrates the "
342+
"system at the boundary temperature, so the boundary must sit "
343+
"where the phase is still cleanly stable, not at the point where a "
344+
"fast diagnostic ramp finally lost (super)stability. It is "
345+
"phase-agnostic (melting, solid-solid, freezing). Lower values "
346+
"place the cut earlier (more margin); higher values place it "
347+
"closer to the collapse. Default 1.5."
348+
),
349+
),
350+
]
351+
onset_fraction: Annotated[
352+
float,
353+
Field(
354+
default=0.85,
355+
gt=0,
356+
le=1.0,
357+
description=(
358+
"Fractional safety margin applied to the detected onset: the "
359+
"adapted upper temperature is "
360+
"T_clean = T0 + onset_fraction * (T_onset - T0). The detected "
361+
"onset is the foot of the deviation in a *fast* diagnostic ramp, "
362+
"but a reversible-scaling sweep then EQUILIBRATES at the boundary "
363+
"for many steps and the metastable phase has more time to "
364+
"nucleate the transition there — so its practical stability "
365+
"limit is somewhat below the ramp onset, and the exact onset is "
366+
"also noisy. Backing the boundary off by a fraction of the "
367+
"super-heated/cooled span makes the adapted sweep robust to both "
368+
"effects. 1.0 disables the margin (cut exactly at the onset); "
369+
"lower values give more margin (and less usable range). "
370+
"Default 0.85."
371+
),
372+
),
373+
]
374+
prescan_steps: Annotated[
375+
int,
376+
Field(
377+
default=20000,
378+
ge=1000,
334379
description=(
335-
"Split each TS sweep into blocks of this width (in Kelvin). "
336-
"The transition detector is called at each block boundary. "
337-
"Set to 0 to run a single sweep with post-hoc detection only."
380+
"Number of MD steps for the pre-flight temperature ramp from "
381+
"T0 to Tf. Typically a little shorter than the production "
382+
"switching length. Note that a *faster* ramp superheats (or "
383+
"supercools) the metastable phase further and yields noisier "
384+
"response-function signals, pushing the detected onset closer "
385+
"to the collapse; if the adapted ts sweep melts/freezes during "
386+
"its equilibration, increase this (or lower onset_level). "
387+
"Default 20000."
338388
),
339389
),
340390
]

calphy/liquid.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,6 @@ def run_averaging(self):
219219
# now assign correct temperature and equilibrate
220220
self.run_zero_pressure_equilibration(lmp)
221221

222-
# create the fluctuation monitor before the pressure-convergence cycle loop
223-
self._create_monitor("liquid")
224-
225222
# converge pressure
226223
self.run_pressure_convergence(lmp)
227224
else:

0 commit comments

Comments
 (0)