inlab-geo / cofi

Common Framework for Inference
https://cofi.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
17 stars 4 forks source link

Optimise `import cofi` by not importing `cofi.solvers` #59

Closed jwhhh closed 2 years ago

jwhhh commented 2 years ago

Currently import cofi takes longer time than expected. The main cause should be:

In cofi/__init__.py:

from .base_problem import BaseProblem

In cofi/base_problem.py:

from .solvers import solvers_table

In cofi/solvers/__init__.py:

from .<solver_name> import <Solver> 

Importing the solvers take time, as they load the underline packages and examine required/optional parameters on the fly.

We now want to optimise this by avoiding direct import of solvers from base_problem.py.

Side note: the reason why we import solvers from base_problem.py is that then we can suggest solvers based on information supplied. We need a workaround.

jwhhh commented 2 years ago

Additionally, avoid importing emcee and arviz when importing cofi.

They are all solved by moving imports into the methods that need them.