Repository navigation
Migrate molecular LASCI and LASSCF to PySCF-Forge - #230
Closed
MatthewRHermes wants to merge 1 commit into
Closed
MatthewRHermes wants to merge 1 commit into
MatthewRHermes wants to merge 1 commit into
Conversation
Collaborator
Author
|
oops wrong repo sry |
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.
Migration of LASSCF from mrh to PySCF-Forge
This is one of a pair of PRs describing the transfer of molecular LASCI and LASSCF code from mrh to PySCF-Forge. The other is EDIT LINK AFTER POSTING. When the task is complete, the PySCF-Forge PR will be retargeted at
origin/masterand its description will be rewritten. The PR into mrh will be accepted and merged only after the PR into PySCF-Forge is accepted and merged. The goal is to open the PR into PySCF-Forge by the end of November 2026 and have the migration completed by the end of December 2026.Scope
Only the synchronous algorithm of LASSCF (
lasscf_sync_o0.py) and the RDM algorithm (lasscf_rdm.py) are being transferred, and thegpu4mrhextension along with all other LASSCF implementation variants, the PBC reimplementation, and all LASSI features will remain in mrh. After migration, mrh will import the transferred code from PySCF-Forge; it will not retain copies. Effort will be made to make this modification invisible to users.Checklist
Code transfer list
Module and method renames happen in step 5. mrh will keep aliases for the old names.
Transferred in their entirety
mrh/my_pyscf/mcscf/productstate.py->pyscf/mcscf/las/productstate.pymrh/my_pyscf/mcscf/lasscf_guess.py->pyscf/mcscf/las/lasscf_guess.pymrh/my_pyscf/mcscf/chkfile.py->pyscf/mcscf/las/chkfile.pymrh/my_pyscf/mcscf/lasscf_rdm.py->pyscf/mcscf/las/lasscf_rdm.pymrh/my_pyscf/mcpdft/laspdft.py->pyscf/mcpdft/laspdft.py(LAS-PDFT only. LASSI-PDFT was split out intomrh/my_pyscf/mcpdft/lassipdft.py, which stays in mrh.)mrh/my_pyscf/grad/lasscf.py->pyscf/grad/lasscf.pyTransferred except for
gpu4mrhcodemrh keeps a hook file of the same name for each of these. The hook defines an mrh subclass that adds the GPU code back by overriding
__init__,_get_h2eff_df,HessianOperator._init_df_andfast_veffa.mrh/my_pyscf/mcscf/lasci.py->pyscf/mcscf/las/lasci.py. TheLASCINoSymm.lassi()convenience method also stays in mrh.mrh/my_pyscf/mcscf/las_ao2mo.py->pyscf/mcscf/las/las_ao2mo.py.get_h2eff_gpuandget_h2eff_gpu_v2stay in mrh.mrh/my_pyscf/mcscf/lasscf_sync_o0.py->pyscf/mcscf/las/lasscf.pyTransferred partially
mrh/my_pyscf/mcscf/__init__.py->pyscf/mcscf/las/__init__.py:_DFLASCIonly. mrh re-exports the same class object, soisinstancechecks keep working.mrh/my_pyscf/mcscf/addons.py->pyscf/mcscf/las/addons.py: everything exceptdebug_lasscf_hessian_andlasscf_hessian_debugger, which stay in mrh. This includesci_outer_productand its helpers, which moved here frommrh/my_pyscf/lassi/op_o0.pyin step 2.mrh/my_pyscf/df/sparse_df.py(sparsedf_array) andmrh/lib/sparsedf.c-> somewhere underpyscf/lib/(destination not yet decided). Marked for step 5 refactoring.mrh/util/la.py: thematrix_svd_control_optionsclosure -> a private Forge module, e.g.pyscf/mcscf/las/_la.py. Marked for step 5 refactoring.Not transferred
gpu4mrh,laspscf.py,lasscf_async,lasscf_sync_o1.py, the PBC LAS code, and all of LASSI, including LASSI-PDFTmrh/my_pyscf/mcpdft/__init__.py, to be revisited in step 5Development workflow
I am performing the transfer and refactor using Claude Code running Opus 5.5. The file
MIGRATION.md, which explained to Claude the goals and strategy of this transfer, is reproduced in its entirety below.MIGRATION.md
Goal
It is imperative to migrate the core features of LASSCF to PySCF-Forge as soon as possible. I have done this sort of thing in the past with MC-PDFT, which once lived here, then moved to PySCF-Forge, then finally to PySCF core. Throughout this project, there are "hook" files that import something from PySCF and print a warning about a migration. The idea is to avoid disrupting anyone's current workflow while prompting them to update for the new home of the method.
"Core features of LASSCF" means (in the folder
my_pyscf/mcscfunless otherwise indicated)lasci.py, excluding all gpu4mrh features (see below)las_ao2mo.py, excluding all gpu4mrh featureslasscf_sync_o0.py, excluding all gpu4mrh features (file should be renamed in PySCF-Forge)productstate.pylasscf_guess.pychkfile.pylasscf_rdm.py, so that maintainers oflassqd_code(see~/gits/lassqd_code) can eventually remove dependence onmrhmy_pyscf/mcpdft/laspdft.py; same reason as abovemy_pyscf/grad/lasscf.pyaddons.pyimplicated in the above__init__.pyimplicated in the aboveMost files will live in a new folder
pyscf/mcscf/lasin PySCF-Forge. The PDFT and gradient code are exceptions: they will live respectively inpyscf/mcpdft/laspdft.pyandpyscf/grad/lasscf.py.laspscf.pyandlasscf_asyncwill not be migrated at this time.gpu4mrhwill also not be migrated, which potentially creates difficulty. We have three potentially competing imperatives:I hope that clever subclassing and/or monkeypatching is enough to satisfy all three imperatives simultaneously, but I'm not sure it will be.
Unit tests and example scripts can be copied (or written from scratch) - they can live in both packages for a time. All other code that is migrated should remain only in Forge. Small "hook" files remaining in
mrh/my_pyscf/mcscfcan define mrh-variant subclasses, but this should only be for the purpose of maintaining features not transfered and should be as minimal as possible otherwise.Workspace
PySCF-Forge LASSCF migration worktree:
/home/herme068/gits/pyscf_ext/pyscf-forge_las-migrationPySCF-Forge LASSCF migration branch:
lasscfmrh LASSCF migration worktree:
/home/herme068/gits/mrh_las-migrationmrh LASSCF migration branch:
las-migrationThese worktrees will be turned into PRs simultaneously against PySCF-Forge origin and mrh origin. When executing test files and running example scripts in either of these worktrees on this machine, PYTHONPATH should prefer both worktrees over the corresponding standard installations, either via some kind of command a la
pyscf-hereor by modifying the environment.Steps
This is a plan; it is subject to change. Open draft PRs against mrhfork/master for PySCF-Forge and origin/dev for mrh, which I will review between each of numbered steps 2-6 below. At each review point, all tests in mrh should always pass, and all examples should produce unchanged results (to within the maximum of the relevant convergence tolerance). Tests and examples should never be removed from mrh at any point, and only modified inasmuch as refactor/cleanup in steps 2 or 5 below require it. Commits should be tagged as each step is completed. In steps 3-5, commits to the two worktree branches should be made simultaneously, in parallel, with matching tags.
lasscf_asyncorlassi), and for any dependencies from mrh not included in the scope list.from the migration, or refactor within mrh to move it out of that layer.
instead of monkeypatching them, if possible.
mrh_las-migrationshould be merged intodev.lasci.py, etc. other than gpu4mrh code and other functionalities marked in step 2 above, willlive exclusively in the Forge worktree.
migration (ignore lint, flake, etc.).
_slowmarker liberally.lasscf_sync_o0should just becomelasscf)pyscf.mcscf.lasshould expose a sensible, intuitive method constructor:pyscf.mcscf.las.LASSCFlassqd_codedepends on:_capture_hamiltonians: We should write an API for this, to givelassqd_codedevelopers the opportunity to retire thehack.
replay_orbital_step: Common sense saysmax_cycle_rdmjk = 0; max_cycle_macro = 1; conv_tol_grad = 0should alwaysaccomplish "take exactly zero RDM steps and one orbital step", so there is no need to write a new API. However, their
implementation doesn't set
conv_tol_grad, and depends instead on default logic for RDM jk convergence after zerocycles. I will ask them to firm this up on their end. In the mean time, we have to avoid breaking it.
localize_init_guessNotes
debugfolder in mrh does not need to be maintained. It represents stuff that I keep aroundjust in case it happens to be useful, but on which I do not depend.