Here’s a documentation for the cassiopeia/__init__.py file:

High-level description

This file serves as the top-level initialization for the Cassiopeia package. It imports and exposes key submodules, sets up version information, and configures the package namespace.

Code Structure

The file imports various submodules of Cassiopeia and makes them available at the top level of the package. It also sets up version information using importlib.metadata and configures the package namespace.

Symbols

Imported submodules

Description

The following submodules are imported and made available at the top level of the Cassiopeia package:

  • preprocess (aliased as pp)
  • solver
  • plotting (aliased as pl)
  • data
  • critique
  • simulator (aliased as sim)
  • tools (aliased as tl)

These imports allow users to access these submodules directly from the Cassiopeia package.

__version__

Description

Stores the version number of the Cassiopeia package.

Internal Logic

The version is retrieved using importlib.metadata.version() with the package name “cassiopeia-lineage”. This allows for dynamic version retrieval based on the installed package metadata.

Package namespace configuration

Description

Configures the package namespace to allow direct access to certain submodules.

Internal Logic

The sys.modules dictionary is updated to allow direct access to the tl, pp, pl, and sim submodules from the Cassiopeia package namespace. This means users can access these submodules directly, e.g., cassiopeia.tl instead of cassiopeia.tools.

Dependencies

DependencyPurpose
importlib.metadataUsed for retrieving the package version
importlib_metadataFallback for Python versions that don’t have importlib.metadata

Error Handling

The code includes a try-except block to handle potential ModuleNotFoundError when importing importlib.metadata. If this import fails, it falls back to using importlib_metadata.

Your response should not exceed 3000 words or 4000 tokens. Focus on providing clear, concise information that can be directly inferred from the code. Include optional sections only when they provide significant value for understanding the code.