|
4 | 4 |
|
5 | 5 | Shared utilities used across VQE, QPE, and future solvers. |
6 | 6 |
|
7 | | -This subpackage contains: |
8 | | - • common.molecules — canonical molecule registry |
9 | | - • common.geometry — unified geometry generators (bond/angle scans) |
10 | | - • common.hamiltonian — single source of truth for Hamiltonian construction |
11 | | - • common.plotting — global plotting + filename/dir management |
12 | | -
|
13 | | -All high-level solvers (VQE, QPE, QSVT, etc.) should import molecule |
14 | | -definitions, geometry logic, Hamiltonians, and plotting helpers from here |
15 | | -to avoid duplication and ensure reproducibility. |
| 7 | +The public exports are resolved lazily so importing high-level packages for |
| 8 | +metadata or CLI help does not also import the quantum chemistry stack. |
16 | 9 | """ |
17 | 10 |
|
18 | 11 | from __future__ import annotations |
19 | 12 |
|
20 | 13 | from importlib.metadata import PackageNotFoundError, version as _pkg_version |
| 14 | +from typing import Any |
21 | 15 |
|
22 | 16 | from . import mpl_env as _mpl_env # noqa: F401 |
| 17 | +from .lazy import LazyExports, list_exports, load_export |
23 | 18 |
|
24 | 19 | try: |
25 | 20 | __version__ = _pkg_version("vqe-pennylane") |
26 | 21 | except PackageNotFoundError: # pragma: no cover |
27 | 22 | __version__ = "0.0.0" |
28 | 23 |
|
29 | 24 |
|
30 | | -# Molecule data + helpers |
31 | | -from .molecules import MOLECULES, get_molecule_config # noqa: F401, E402 |
32 | | - |
33 | | -# Geometry (bond length, angle scans, parametrized coordinates) |
34 | | -from .geometry import generate_geometry # noqa: F401, E402 |
35 | | - |
36 | | -# Hamiltonian construction (PennyLane + OpenFermion fallback) |
37 | | -from .hamiltonian import ( # noqa: F401, E402 |
38 | | - build_hamiltonian, |
39 | | - get_exact_spectrum, |
40 | | - summarize_registry_coverage, |
41 | | -) |
42 | | -from .benchmarks import ( # noqa: F401, E402 |
43 | | - analyze_qpe_result, |
44 | | - exact_ground_energy_for_problem, |
45 | | - ionization_energy_panel, |
46 | | - qpe_branch_candidates, |
47 | | - qpe_calibration_plan, |
48 | | - summarize_problem, |
49 | | - summary_stats, |
50 | | - timed_call, |
51 | | -) |
52 | | -from .metrics import compute_fidelity # noqa: F401, E402 |
53 | | -from .problem import ResolvedProblem, resolve_problem # noqa: F401, E402 |
54 | | - |
55 | | -# Molecule visualization |
56 | | -from .molecule_viz import ( |
57 | | - plot_molecule, |
58 | | - infer_bonds, |
59 | | - infer_angles_from_bonds, |
60 | | -) # noqa: F401, E402 |
61 | | - |
62 | | -# Plotting utilities shared across VQE + QPE |
63 | | -from .plotting import build_filename, save_plot # noqa: F401, E402 |
64 | | -from .naming import format_molecule_name, format_token # noqa: F401, E402 |
65 | | - |
66 | | -__all__ = [ |
| 25 | +_EXPORTS: LazyExports = { |
67 | 26 | # Molecules |
68 | | - "MOLECULES", |
69 | | - "get_molecule_config", |
| 27 | + "MOLECULES": ("common.molecules", "MOLECULES"), |
| 28 | + "get_molecule_config": ("common.molecules", "get_molecule_config"), |
70 | 29 | # Geometry |
71 | | - "generate_geometry", |
| 30 | + "generate_geometry": ("common.geometry", "generate_geometry"), |
72 | 31 | # Hamiltonian |
73 | | - "build_hamiltonian", |
74 | | - "get_exact_spectrum", |
75 | | - "summarize_registry_coverage", |
76 | | - "timed_call", |
77 | | - "summary_stats", |
78 | | - "qpe_branch_candidates", |
79 | | - "analyze_qpe_result", |
80 | | - "qpe_calibration_plan", |
81 | | - "exact_ground_energy_for_problem", |
82 | | - "ionization_energy_panel", |
83 | | - "summarize_problem", |
84 | | - "compute_fidelity", |
85 | | - "ResolvedProblem", |
86 | | - "resolve_problem", |
| 32 | + "build_hamiltonian": ("common.hamiltonian", "build_hamiltonian"), |
| 33 | + "get_exact_spectrum": ("common.hamiltonian", "get_exact_spectrum"), |
| 34 | + "summarize_registry_coverage": ( |
| 35 | + "common.hamiltonian", |
| 36 | + "summarize_registry_coverage", |
| 37 | + ), |
| 38 | + # Benchmarks/helpers |
| 39 | + "timed_call": ("common.benchmarks", "timed_call"), |
| 40 | + "summary_stats": ("common.benchmarks", "summary_stats"), |
| 41 | + "qpe_branch_candidates": ("common.benchmarks", "qpe_branch_candidates"), |
| 42 | + "analyze_qpe_result": ("common.benchmarks", "analyze_qpe_result"), |
| 43 | + "qpe_calibration_plan": ("common.benchmarks", "qpe_calibration_plan"), |
| 44 | + "exact_ground_energy_for_problem": ( |
| 45 | + "common.benchmarks", |
| 46 | + "exact_ground_energy_for_problem", |
| 47 | + ), |
| 48 | + "ionization_energy_panel": ("common.benchmarks", "ionization_energy_panel"), |
| 49 | + "summarize_problem": ("common.benchmarks", "summarize_problem"), |
| 50 | + "compute_fidelity": ("common.metrics", "compute_fidelity"), |
| 51 | + "ResolvedProblem": ("common.problem", "ResolvedProblem"), |
| 52 | + "resolve_problem": ("common.problem", "resolve_problem"), |
87 | 53 | # Plotting |
88 | | - "build_filename", |
89 | | - "save_plot", |
90 | | - "format_molecule_name", |
91 | | - "format_token", |
| 54 | + "build_filename": ("common.plotting", "build_filename"), |
| 55 | + "save_plot": ("common.plotting", "save_plot"), |
| 56 | + "format_molecule_name": ("common.naming", "format_molecule_name"), |
| 57 | + "format_token": ("common.naming", "format_token"), |
92 | 58 | # Molecule visualization |
93 | | - "plot_molecule", |
94 | | - "infer_bonds", |
95 | | - "infer_angles_from_bonds", |
| 59 | + "plot_molecule": ("common.molecule_viz", "plot_molecule"), |
| 60 | + "infer_bonds": ("common.molecule_viz", "infer_bonds"), |
| 61 | + "infer_angles_from_bonds": ("common.molecule_viz", "infer_angles_from_bonds"), |
| 62 | +} |
| 63 | + |
| 64 | +__all__ = [ |
| 65 | + "__version__", |
| 66 | + *_EXPORTS.keys(), |
96 | 67 | ] |
| 68 | + |
| 69 | + |
| 70 | +def __getattr__(name: str) -> Any: |
| 71 | + return load_export( |
| 72 | + package_name=__name__, |
| 73 | + package_globals=globals(), |
| 74 | + exports=_EXPORTS, |
| 75 | + name=name, |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +def __dir__() -> list[str]: |
| 80 | + import sys |
| 81 | + |
| 82 | + return list_exports(sys.modules[__name__], _EXPORTS) |
0 commit comments