Prevent MP2 localizer deprecation warnings during import - #691
Prevent MP2 localizer deprecation warnings during import#691David Williams-Young (wavefunction91) with Copilot wants to merge 5 commits into
Conversation
Co-authored-by: wavefunction91 <6208701+wavefunction91@users.noreply.github.com>
|
Copilot Pick this PR back up and finish it. Do not rebuild or reinstall qdk-chemistry, and do not run the full test suite, documentation build, or broad pre-commit set on the agent runner. Use the focused regression test already added in this PR as the local validation: |
Co-authored-by: wavefunction91 <6208701+wavefunction91@users.noreply.github.com>
Finished in 613e4a9. Source inspection confirms stub introspection uses the non-warning factory path, while public creation retains one Python warning and one C++ log warning. The requested local test could not run because pytest is absent, so I did not rebuild or install. The macOS failure was caused by the new test inheriting a disabled global logger; the test now establishes and restores warning-level logging. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b7eef1a1-8f39-42f8-8893-261a5f5a7f35
There was a problem hiding this comment.
Pull request overview
This PR prevents MP2 natural-orbital localizer deprecation warnings from being emitted during qdk_chemistry import-time registry stub generation by introducing an internal “introspection” construction path that bypasses deprecation emission, while preserving existing deprecation behavior for explicit user creation via the public factory APIs.
Changes:
- Added an internal factory creation path (
FactoryAccess/_create_for_introspection) that constructs instances without triggering deprecation warnings/logs. - Updated registry stub generation to reuse a single introspected instance for both type and settings inspection.
- Added regression tests covering warning-free stub generation and preserved explicit deprecation behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/tests/test_mp2_natural_orbital_deprecation.py | Adds regression tests for warning-free stub generation and one-time deprecation on explicit creation. |
| python/src/qdk_chemistry/algorithms/registry.py | Refactors settings inspection into a helper and adds internal introspection instance creation. |
| python/src/qdk_chemistry/init.py | Switches stub generation to use internal introspection construction + reused instance settings inspection. |
| python/src/pybind11/algorithms/factory_bindings.hpp | Exposes an internal _create_for_introspection binding that bypasses deprecation emission. |
| cpp/include/qdk/chemistry/algorithms/algorithm.hpp | Moves deprecation logging into public create() and adds FactoryAccess to call internal create_impl() without logging. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c61ff7f1-1ce7-4701-859b-0508efa9e4b9
| * @param name The name to identify the desired algorithm implementation. | ||
| * @return A unique pointer to the created algorithm instance. | ||
| * @throws std::runtime_error if the name is not found in the registry. | ||
| */ | ||
| static return_type create(const std::string& name = "") { | ||
| static return_type create(const std::string& name = "", | ||
| bool suppress_warnings = false) { |
Import-time registry stub generation constructed the deprecated MP2 natural-orbital localizer through the public factory path, emitting Python and C++ warnings.
Factory lifecycle
qdk_mp2_natural_orbitalscreation.Stub generation
Regression coverage
Original prompt