google / qhbm-library

Quantum Hamiltonian-Based Models built on TensorFlow Quantum
https://qhbm-library.readthedocs.io/en/latest/
Apache License 2.0
40 stars 15 forks source link

Organize into submodules #196

Closed zaqqwerty closed 2 years ago

zaqqwerty commented 2 years ago

Part of #99

The number of files was causing imports to become tedious. This pull request creates two new submodules, model and infer, and moves related files into them. New __init__ files have been added to these modules to simplify user imports: for example, instead of

from qhbmlib import circuit_infer
from qhbmlib import energy_infer
from qhbmlib import hamiltonian_infer

my_qnn= circuit_infer.QuantumInference(...)
my_ebm = energy_infer.BernoulliEnergyInference(...)
my_qhbm = hamiltonian_infer.QHBM(...)

we can now have

from qhbmlib import infer

my_qnn = infer.QuantumInference(...)
my_ebm = infer.BernoulliEnergyInference(...)
my_qhbm = infer.QHBM(...)

For a followup pull request, any opinions on where the remaining top-level files should go?

zaqqwerty commented 2 years ago

Made a few changes to address your comments:

Also, decided to remove architectures and hamiltonian. Only one function is used within the library, get_hardware_efficient_model_unitary, so I moved this into the test_util file. Otherwise, the functions in architectures and hamiltonian were used only occasionally in research code, so if we were to keep any of it I think they only make sense in the baselines directory. To this end I opened #197.

Left a comment on the discussion of adding __all__ to init files.

zaqqwerty commented 2 years ago

After our discussion, settled on package imports (from qhbmlib import inference) throughout the test files, stuck with module imports (from qhbmlib.inference import qhbm) in the library code files, which ends up being consistent with how things look to be done in TFP.