Package phi

Open-source simulation toolkit built for optimization and machine learning applications.

Use one of the following imports:

  • from phi.flow import * for NumPy mode
  • from phi.tf.flow import * for TensorFlow mode
  • from phi.torch.flow import * for PyTorch mode
  • from phi.jax.flow import * for Jax mode

Project homepage: https://github.com/tum-pbs/PhiFlow

Documentation overview: https://tum-pbs.github.io/PhiFlow

PyPI: https://pypi.org/project/phiflow/

Expand source code
"""
Open-source simulation toolkit built for optimization and machine learning applications.

Use one of the following imports:

* `from phi.flow import *`  for NumPy mode
* `from phi.tf.flow import *`  for TensorFlow mode
* `from phi.torch.flow import *` for PyTorch mode
* `from phi.jax.flow import *` for Jax mode

Project homepage: https://github.com/tum-pbs/PhiFlow

Documentation overview: https://tum-pbs.github.io/PhiFlow

PyPI: https://pypi.org/project/phiflow/
"""

import os as _os


with open(_os.path.join(_os.path.dirname(__file__), 'VERSION'), 'r') as version_file:
    __version__ = version_file.read()


def verify():
    """
    Checks your configuration for potential problems and prints a summary.

    To run verify without importing `phi`, run the script `tests/verify.py` included in the source distribution.
    """
    import sys
    from ._troubleshoot import assert_minimal_config, troubleshoot
    try:
        assert_minimal_config()
    except AssertionError as fail_err:
        print("\n".join(fail_err.args), file=sys.stderr)
        return
    print(troubleshoot())


def detect_backends() -> tuple:
    """
    Registers all available backends and returns them.
    This includes only backends for which the minimal requirements are fulfilled.

    Returns:
        `tuple` of `phi.math.backend.Backend`
    """
    try:
        from .torch import TORCH
    except ImportError:
        pass
    try:
        from .tf import TENSORFLOW
    except ImportError:
        pass
    try:
        from .jax import JAX
    except ImportError:
        pass
    from .math.backend import BACKENDS
    return tuple(BACKENDS)

Sub-modules

phi.field

The fields module provides a number of data structures and functions to represent continuous, spatially varying data …

phi.flow

Main PhiFlow import: from phi.flow import *

phi.flow_1

Compatibility import for PhiFlow 1 projects: from phi.flow_1 import *

phi.geom

Differentiable geometry package …

phi.jax

Jax integration …

phi.math

Vectorized operations, tensors with named dimensions …

phi.physics

Contains built-in physics functions, e.g. for fluids. The actual physics functions are located in the sub-modules of phi.physics. A common trait of …

phi.struct

Deprecated

phi.tf

TensorFlow integration …

phi.torch

PyTorch integration …

phi.vis

Visualization: plotting, interactive user interfaces …

Functions

def detect_backends() ‑> tuple

Registers all available backends and returns them. This includes only backends for which the minimal requirements are fulfilled.

Returns

tuple of Backend

Expand source code
def detect_backends() -> tuple:
    """
    Registers all available backends and returns them.
    This includes only backends for which the minimal requirements are fulfilled.

    Returns:
        `tuple` of `phi.math.backend.Backend`
    """
    try:
        from .torch import TORCH
    except ImportError:
        pass
    try:
        from .tf import TENSORFLOW
    except ImportError:
        pass
    try:
        from .jax import JAX
    except ImportError:
        pass
    from .math.backend import BACKENDS
    return tuple(BACKENDS)
def verify()

Checks your configuration for potential problems and prints a summary.

To run verify without importing phi, run the script tests/verify.py included in the source distribution.

Expand source code
def verify():
    """
    Checks your configuration for potential problems and prints a summary.

    To run verify without importing `phi`, run the script `tests/verify.py` included in the source distribution.
    """
    import sys
    from ._troubleshoot import assert_minimal_config, troubleshoot
    try:
        assert_minimal_config()
    except AssertionError as fail_err:
        print("\n".join(fail_err.args), file=sys.stderr)
        return
    print(troubleshoot())