Extend script_mode to liquid, alchemy, and mode:ts#248
Open
ligerzero-ai wants to merge 2 commits into
Open
Conversation
Previously script_mode (which writes averaging.lmp/integration.lmp for execution by an external lammps_executable) was wired up only for the solid phase. Liquid and alchemy phases hardcoded the in-process LammpsLibrary path, so users running with a custom LAMMPS binary could only do solid-phase free-energy calculations. Changes: - helpers.py: LammpsScript now polyfills the LammpsLibrary Python API. Unknown attribute access lowers to a LAMMPS command (so lmp.velocity(...) and lmp.run(N) work in script_mode the same way they do in-process). Adds no-op close() and clear() to mirror LammpsLibrary teardown. - liquid.py: run_averaging and run_integration now propagate script_mode to create_object and emit averaging.lmp / integration.lmp at the end of each step. Iterative pyscal-based solid-fraction check is skipped under script_mode (cannot run mid-script). melting_cycle is rejected with a clear ValueError under script_mode since it requires Python-driven feedback. - alchemy.py: same propagation and script-emission for run_averaging and run_integration. Pair-style handling is unchanged and remains pair-style-agnostic, so any LAMMPS binary that supports the user's pair_style (EAM, MEAM, SNAP, ACE, GRACE, ML-PACE, etc.) can be plugged in via the existing lammps_executable / mpi_executable input fields. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
reversible_scaling, temperature_scaling, and the alchemy-side hardcoded script_mode=False sites were the last places where in-process LAMMPS was forced even when the calculation requested script_mode. They are now the same script_mode-aware pattern as the rest of the codebase: emit a single static LAMMPS script and return so the user's lammps_executable can run it. - phase.py reversible_scaling: writes reversible_scaling_<iteration>.lmp - phase.py temperature_scaling: writes temperature_scaling_<iteration>.lmp - alchemy-side reversible_scaling at the same site picks up the same fix automatically (replace_all) This unblocks running mode:ts free-energy temperature sweeps end-to-end under script_mode, which is the workflow needed to drive an external ML-potential-built lammps binary (e.g. GRACE, ACE, MACE) for phase- boundary calculations. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Currently
script_mode: trueonly works formode: fewithreference_phase: solid. For other phases/modes the code unconditionally constructs apylammpsmpi.LammpsLibrary— which requires LAMMPS built as a shared library with Python bindings (PKG_PYTHON=ON,BUILD_LIB=ON,BUILD_SHARED_LIBS=ON).This is restrictive for users running ML interatomic potentials whose LAMMPS plugins ship only as a regular executable build (e.g.
pair_graceagainst a TensorFlow SavedModel;pair_mace; etc.). For these the natural workflow isscript_mode: true+lammps_executable: <path>— calphy emits a.lmpscript and the user'slmpruns it.This PR extends that workflow to liquid, alchemy, and
mode: tsso they all honourscript_mode: trueend-to-end and shell out vialammps_executable.Changes
Extend script_mode to liquid and alchemy phases (1cd7612)
helpers.py:LammpsScriptgains a__getattr__polyfill so unknown attributes (e.g.lmp.velocity(...),lmp.run(N)) lower to the equivalentcommand(...)call. Lets the liquid/alchemy routines use the same Python-style API as the in-processLammpsLibrarypath without each call site needing two branches.liquid.py: propagatescript_modeinto the LAMMPS factory; emitaveraging.lmpandintegration.lmpat the end of each routine when in script mode.alchemy.py: same propagation pattern.Extend script_mode to mode:ts (76b0ad7)
phase.py:reversible_scalingandtemperature_scalingwere the last sites hardcodingscript_mode=False; replace withscript_mode=self.calc.script_modeand write the resultingreversible_scaling_<i>.lmp/temperature_scaling_<i>.lmp.Default behaviour is unchanged:
script_modestill defaults tofalse, all existing in-process workflows go through the sameLammpsLibrarypath as before.Tests
pytest tests/— all 96 existing tests pass on this branch.The branch is based on commit 0911ac4;
mainhas since moved 9 commits ahead (phase_diagram.pyrework + version bump 1.7.2 → 1.7.3 + tdb test renames). None of the upstream changes touch the files modified here (phase.py,liquid.py,alchemy.py,helpers.py), so this should merge cleanly — happy to rebase if preferred.Out-of-band validation
Used to drive a 48-potential calphy
mode: tscampaign computing F(T) BCC/FCC for GRACE Fe ML interatomic potentials against a custom LAMMPS binary that doesn't have Python bindings.