Skip to content

adapt for QCSchema v2 and Python v3.14#110

Merged
AlexHeide merged 22 commits into
psi-rking:masterfrom
loriab:py314_v1v2
Apr 17, 2026
Merged

adapt for QCSchema v2 and Python v3.14#110
AlexHeide merged 22 commits into
psi-rking:masterfrom
loriab:py314_v1v2

Conversation

@loriab

@loriab loriab commented Feb 28, 2026

Copy link
Copy Markdown
Collaborator

Goals

Sorry for the monster PR. Basic goals are as it says on the tin:

  • let optking work with QCSchema v2. It's set up to emit v1 if fed v1 and emit v2 if fed v2, no cross like QCEngine or Psi4 itself allows.
  • let optking work with Python 3.14. Pydantic v1 API itself doesn't work with py314+, so using QCSchema v2 is the only way.
  • let optking continue working in old environments. Unlike QCManyBody, whose adaptation requires qcel v0.50.0rc3, optking should mostly keep working. This isn't guaranteed, but I do have this branch installed in the below, which isn't cutting edge:
numpy                     1.26.4          py311h64a7726_0    conda-forge
optking                   0.4.2+0.g6200e33.dirty           dev_0    <develop>
pint                      0.24.1             pyhd8ed1ab_1    conda-forge
psi4                      1.9.1           py311he3e7f2e_3    conda-forge
pydantic                  2.8.2              pyhd8ed1ab_0    conda-forge
python                    3.11.9          hb806964_0_cpython    conda-forge
qcelemental               0.28.0             pyhd8ed1ab_0    conda-forge
qcengine                  0.34.0             pyhd8ed1ab_0    conda-forge

Notes

  • fixed your CI (fair since it was my L2 build that broke it) and RTD build
  • added a bit of v2 documentation
  • To understand the difference between v1 and v2, you can consult the cheat sheet (unless you hate figures, in which case use the migration guide or changelog). https://github.com/MolSSI/QCElemental/blob/next2026/docs/qcschema_cheatsheet_9Jan2026.png
  • functions now take a schema version: Molsys.from_psi4, Molsys.to_schema, CustomHelper.__init__ (default to 1), CustomHelper.from_dict (default to 1), from_dict (default to 1), from_psi4 (default to 1), ComputeWrapper/Psi4/QCEngine/UserComputer.__init__/init_full now take schema version and protocols since OptimizationProtocols are a new class, make_computer_from_dict likewise take version and protocols
  • functions that detect schema internally and alter output: write_opt_xyz_trajectory, Helper.to_dict, from_schema, prepare_opt_output, initialize_from_psi4 (acts on whether psi4 is pre- or post- my Py314 and QCSchema v2 psi4/psi4#3341 PR), optimize_qcengine (detects by schema structure), make_computer (detects MBE vs plain opt and 1 vs 2), ComputeWrapper/Psi4/QCEngine/UserComputer.generate_schema_input/generate_schema_input_for_procedure
  • Please take a close look at prepare_opt_output. Is there a better way to collect properties? In particular, it'd be nice to get return_gradient from optking innards, not from trajectory, in case of an energy driver or a single atom or absent trajectory. Also, it'd be nice to get rmsd, max forces etc. against which convergence is judged. properties needs to be very reliably populated.
  • ManyBody optimizations are back again with v2. These are now first-class specifiable through OptimizationInput/Result rather than the non-unified and experimental GeneralizedOptimizationInput/Result for v1 that you merged before. I'm plain killing off the GenOpt for v1, so those tests are no more.
  • I added utils.psi4_runs_v2_qcschema to a lot of your tests. note that unlike QCEngine, v1 and v2 aren't being tested simultaneously through parameterization. Rather, if it detects a psi4 that can run v2, it runs it, and otherwise it runs v1. A corollary is that v2 isn't much tested in CI b/c there is not conda psi4 with v2 released. But this is clean for a local psi4 with py314 and QCSchema v2 that I have. A few tests do parameterize v1 and v2 explicitly, but it isn't most.
  • I've added intrafrag_hess back in the psi4 py314 PR read_options, so that bit of logic can go away soon (or now if you're ok with failing tests)
  • packaging added to easily compare versions
  • I added five new JSON files for v2 and included some directions for generating v2 from v1. Note that b/c GenOpt is retired, the LiF v1 files are now unused.
  • I added a new testing lane base-next, but it isn't testing a lot b/c no v2 psi4 available

Known Problems

  • with my old py311 env with no other modernized packages (conda list above), there's an error with sf4_quasilinear that doesn't really look related to these changes. I'm ignoring for now.
  • the test_atom is failing when running through v2 because you're setting an error and computing energy rather than setting a gradient. this'd be good to fix medium-term

Next Steps

  • QCElemental 0.50.0rc3 and QCManyBody 0.6.1 needed for fullest performance are released.
  • QCEngine 0.50.0rc2 is nearly there.
  • optking, then, is my last piece needed for Psi4 with QCSchema v2 or Py 3.14 . It'd be nice to get a v0.5 release of this in the next couple weeks. I can work on Psi4 with internal optking builds for a while. How does that timeframe sound?

Added After Above

  • Thank goodness you had done all that options prep for Pydantic v2. I needed to convert all the references in psi4's read_options to your v2 file since Psi4 is entirely v2, and the documentation tools (like Pyd itself) can't face both at once.

@codecov

codecov Bot commented Feb 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.79070% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.12%. Comparing base (6200e33) to head (555d1d0).
⚠️ Report is 23 commits behind head on master.

Files with missing lines Patch % Lines
optking/optwrapper.py 55.95% 37 Missing ⚠️
optking/compute_wrappers.py 52.94% 24 Missing ⚠️
optking/opt_helper.py 71.79% 11 Missing ⚠️
optking/molsys.py 42.85% 4 Missing ⚠️
optking/optimize.py 50.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #110      +/-   ##
==========================================
- Coverage   82.74%   82.12%   -0.62%     
==========================================
  Files          36       36              
  Lines        7950     8068     +118     
==========================================
+ Hits         6578     6626      +48     
- Misses       1372     1442      +70     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread optking/optwrapper.py Outdated
Comment thread optking/tests/test_2_hessians.py
@loriab loriab marked this pull request as ready for review March 10, 2026 02:03
@loriab loriab requested review from AlexHeide and psi-rking March 13, 2026 06:21

@psi-rking psi-rking left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming you can get this to run with v1 and v2 QCSchema, looks good to me!

On the output, it would be good to double-check that this is the best source of output data, but I don't think this need hold up your pull request here. Any tweaks there should not involve changes to format, right?

from qcelemental.models.v2 import Molecule, OptimizationInput, Model, AtomicSpecification

# WARNING. The user MUST set fix_com and fix_orientation to True.
# optimization will almost certainly fail otherwise

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why must orientation be fixed? Because qcengine doesn't guarantee gradients come back with the same COM/orientation? Or because qcengine has its own orientation? Just wondering.

@loriab loriab Mar 21, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just copying the warning from the v1 snippet. But yes, it's b/c input Cart w/o fix_* (or w/False) will return gradient in whatever the QC program's natural orientation is. fix_*=True demands results in input Cart orientation. At least one of your routes imposes the fix_*=True, but I didn't change or enforce that more or universally.


result = optking.optimize_psi4("ccsd")
print(result["trajectory"][-1].keys())
trajkey = "trajectory" if _schver == 1 else "trajectory_results"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change was getting a little annoying, I bet?

Comment thread optking/optwrapper.py
if spec_schema_name == "qcschema_many_body_specification":
model = "(proc_spec_in_options)"
options = opt_input["specification"]["specification"]
if "model" in (qc := options["specification"]): # single spec

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that I understand what this is doing; pretty cool!

psi-rking
psi-rking previously approved these changes Mar 18, 2026
@loriab loriab mentioned this pull request Mar 21, 2026
40 tasks
@AlexHeide

Copy link
Copy Markdown
Collaborator

When I was last doing docs updates, the docstrings in v2/optparams.py didn't get all the updates that v1 received since only v1 was visible online. v2 should now render correctly. I've been having issues with the sphinx substitutions with autodoc_pydantic. I'm not sure if you've run into this as well Lori but I've resorted to using explicit :py:attr:name ` for now.

@AlexHeide

Copy link
Copy Markdown
Collaborator

I'm going to approve and will come back later to check SF4 quasilinear. That test breaking is not surprising - just a reminder to get molsym integrated.

AlexHeide
AlexHeide previously approved these changes Apr 16, 2026

@AlexHeide AlexHeide left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all the code updates and keeping optking up to date with QC*

@AlexHeide

Copy link
Copy Markdown
Collaborator

LGTM. Now that I've added some things I can't review though 😄

@psi-rking

psi-rking commented Apr 17, 2026 via email

Copy link
Copy Markdown
Owner

@loriab

loriab commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator Author

LGTM. Are we ready to merge?

The only thing I've though of that I haven't tested lately is new optking with old/current psi4. Though probably your CI covers that ... I have so many versions running around that I've lost reasoning capacity. I've just done a quick test locally, and it looks good.

I think it's ready for merge and tag. And if we're lucky it'll need zero-to-minimal tuneups for the next Psi4 release. Thanks!

@AlexHeide AlexHeide merged commit 753c7c9 into psi-rking:master Apr 17, 2026
6 checks passed
@loriab loriab deleted the py314_v1v2 branch April 29, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants