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
9 changes: 9 additions & 0 deletions calphy/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,11 @@ def check_if_melted(self, lmp, filename):
aborted with a MeltedError. Detection can be turned off by setting
``tolerance.solid_fraction: 0``.
"""
# Disabled (solid_fraction <= 0): the comparison below can never fire, so do not run the
# structure analysis at all. It is not free, and pyscal3 can segfault in find.neighbors on
# some LAMMPS triclinic dumps, killing a run over a check that could not have stopped it.
if self.calc.tolerance.solid_fraction <= 0:
return
solids = ph.find_solid_fraction(os.path.join(self.simfolder, filename))
if solids / self.natoms < self.calc.tolerance.solid_fraction:
self.lammps_close(lmp=lmp)
Expand All @@ -569,7 +574,11 @@ def check_if_solidfied(self, lmp, filename):

If the solid fraction in ``filename`` exceeds
``tolerance.liquid_fraction`` the run is aborted with a SolidifiedError.
Disabled (``liquid_fraction >= 1``), the analysis is skipped, as in
``check_if_melted``.
"""
if self.calc.tolerance.liquid_fraction >= 1:
return
solids = ph.find_solid_fraction(os.path.join(self.simfolder, filename))
if solids / self.natoms > self.calc.tolerance.liquid_fraction:
self.lammps_close(lmp=lmp)
Expand Down
46 changes: 46 additions & 0 deletions tests/test_disabled_phase_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""A disabled phase-stability check must not run the structure analysis.

`tolerance.solid_fraction: 0` (or `liquid_fraction: 1`) makes the comparison in
check_if_melted / check_if_solidfied impossible to trigger, but the solid fraction
was still computed with pyscal3 -- which segfaults in find.neighbors on some LAMMPS
triclinic dumps (Mg2Si antifluorite, 60-degree primitive cell), killing the run.
"""
from types import SimpleNamespace

import pytest

import calphy.phase as phase_mod
from calphy.phase import Phase


def _fake(solid_fraction=0.0, liquid_fraction=1.0):
tol = SimpleNamespace(solid_fraction=solid_fraction, liquid_fraction=liquid_fraction)
return SimpleNamespace(calc=SimpleNamespace(tolerance=tol), simfolder="/nonexistent", natoms=10)


def _explode(_):
raise AssertionError("find_solid_fraction must not be called when the check is disabled")


def test_disabled_melt_check_skips_structure_analysis(monkeypatch):
monkeypatch.setattr(phase_mod.ph, "find_solid_fraction", _explode)
Phase.check_if_melted(_fake(solid_fraction=0.0), lmp=None, filename="traj.temp.dat")


def test_disabled_solidification_check_skips_structure_analysis(monkeypatch):
monkeypatch.setattr(phase_mod.ph, "find_solid_fraction", _explode)
Phase.check_if_solidfied(_fake(liquid_fraction=1.0), lmp=None, filename="traj.temp.dat")


def test_enabled_melt_check_still_runs(monkeypatch):
called = []
monkeypatch.setattr(phase_mod.ph, "find_solid_fraction", lambda f: called.append(f) or 10)
Phase.check_if_melted(_fake(solid_fraction=0.7), lmp=None, filename="traj.temp.dat")
assert called == ["/nonexistent/traj.temp.dat"]


def test_enabled_solidification_check_still_runs(monkeypatch):
called = []
monkeypatch.setattr(phase_mod.ph, "find_solid_fraction", lambda f: called.append(f) or 0)
Phase.check_if_solidfied(_fake(liquid_fraction=0.05), lmp=None, filename="traj.temp.dat")
assert called == ["/nonexistent/traj.temp.dat"]
Loading