diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d581799d..d1e848e2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -23,7 +23,7 @@ jobs: uses: actions/cache@v2 with: path: ~/.cache/pip - key: pip-cache + key: pip-cache-datadriven - name: Install additional dependencies run: | pip install coverage diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 2cc108b7..760e96b9 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -113,7 +113,7 @@ jobs: uses: actions/cache@v2 with: path: ~/.cache/pip - key: pip-cache + key: pip-cache-datadriven - name: Update run: pip install --upgrade --upgrade-strategy eager -e . - name: Run tests @@ -421,7 +421,7 @@ jobs: uses: actions/cache@v2 with: path: ~/.cache/pip - key: pip-cache + key: pip-cache-datadriven - name: Update run: pip install --upgrade --upgrade-strategy eager -e . - name: Run tests @@ -439,7 +439,7 @@ jobs: uses: actions/cache@v2 with: path: ~/.cache/pip - key: pip-cache + key: pip-cache-datadriven - name: Update run: | pip install --upgrade --upgrade-strategy eager -e . diff --git a/.github/workflows/update-cache.yml b/.github/workflows/update-cache.yml index a1c81375..1f77975b 100644 --- a/.github/workflows/update-cache.yml +++ b/.github/workflows/update-cache.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7'] + python-version: ['3.10'] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -24,3 +24,27 @@ jobs: with: path: ~/.cache/pip key: pip-cache + + cache-dependencies-data-driven: + timeout-minutes: 15 + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10'] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -e '.[datadriven]' + python -m pip install notebook + python -m pip install testbook + python -m pip install requests + - uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: pip-cache-datadriven diff --git a/README.md b/README.md index 7eee2fde..afcbf50f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,12 @@ ProgPy combines NASAs prog_models and prog_algs packages into a single python pa ## Installation `pip3 install progpy` +or + +`pip3 install progpy[datadriven]` + +to include dependencies for data driven models + ## [Documentation](https://nasa.github.io/progpy/) See documentation [here](https://nasa.github.io/progpy/) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..8c2dbe01 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,68 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "progpy" +version = "1.7.0-pre" +dependencies = [ + "scipy", + "pandas", # For data downloading features + "matplotlib", + "requests", # For data downloading features + "chaospy", # For PCE + "fastdtw", # For DTW error calculation + "filterpy" +] +requires-python = ">=3.7, <3.12" +authors = [ + {name = "Christopher Teubert", email = "christopher.a.teubert@nasa.gov"}, + {name = "Katelyn Griffith", email = "katelyn.j.griffith@nasa.gov"} + , + {name = "Matteo Corbetta"}, + {name = "Chetan Kulkarni"}, + {name = "Portia Banerjee"}, + {name = "Jason Watkins"}, + {name = "Matthew Daigle"} +] +maintainers = [ + {name = "Christopher Teubert", email = "christopher.a.teubert@nasa.gov"}, + {name = "Katelyn Griffith", email = "katelyn.j.griffith@nasa.gov"} +] +description = "The NASA Prognostic Package (ProgPy) is a python prognostics framework focused on building, using, and evaluating models and algorithms for prognostics (computation of remaining useful life) and health management of engineering systems, and provides a set of prognostics models for select components and prognostics algorithms developed within this framework, including uncertainty propagation." +readme = "README.md" +license = {text = "NOSA"} +keywords = ['prognostics', 'diagnostics', 'fault detection', 'fdir', 'physics modeling', 'prognostics and health management', 'PHM', 'health management', 'surrogate modeling', 'model tuning', 'simulation', 'ivhm'] +classifiers = [ + 'Development Status :: 5 - Production/Stable', + + 'Intended Audience :: Science/Research', + 'Intended Audience :: Developers', + 'Intended Audience :: Manufacturing', + + 'Topic :: Scientific/Engineering', + 'Topic :: Scientific/Engineering :: Artificial Intelligence', + 'Topic :: Scientific/Engineering :: Physics', + + 'License :: Other/Proprietary License ', + + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3 :: Only' +] + +[project.optional-dependencies] +datadriven = [ + "tensorflow; platform_system!='Darwin' or platform_machine!='arm64'", + "tensorflow-macos; platform_system=='Darwin' and platform_machine=='arm64'"] + +[project.urls] +Homepage = "https://nasa.github.io/progpy/" +Documentation = "https://nasa.github.io/progpy/" +Repository = "https://github.com/nasa/progpy" +Issues = "https://github.com/nasa/progpy/issues" +Organization = "https://www.nasa.gov/content/diagnostics-prognostics" diff --git a/setup.py b/setup.py deleted file mode 100644 index 92915d35..00000000 --- a/setup.py +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright © 2021 United States Government as represented by the Administrator of the -# National Aeronautics and Space Administration. All Rights Reserved. - -from setuptools import setup, find_packages -import pathlib - -here = pathlib.Path(__file__).parent.resolve() - -# Get the long description from the README file -long_description = (here / 'README.md').read_text(encoding='utf-8') - -INSTALL_REQS = [ - 'scipy', - 'pandas', # For data downloading features - 'matplotlib', - 'requests', # For data downloading features - 'chaospy', # For PCE - 'fastdtw', # For DTW error calculation - "tensorflow; platform_system!='Darwin' or platform_machine!='arm64'", - "tensorflow-macos; platform_system=='Darwin' and platform_machine=='arm64'", - "filterpy", - ] - -setup( - name='progpy', - version='1.7.0-pre', - description='The NASA Prognostic Package (ProgPy) is a python prognostics framework focused on building, using, and evaluating models and algorithms for prognostics (computation of remaining useful life) and health management of engineering systems, and provides a set of prognostics models for select components and prognostics algorithms developed within this framework, including uncertainty propagation.', - long_description=long_description, - long_description_content_type='text/markdown', - url='https://nasa.github.io/progpy/', - author='Christopher Teubert', - author_email='christopher.a.teubert@nasa.gov', - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Science/Research', - 'Intended Audience :: Developers', - 'Intended Audience :: Manufacturing', - 'Topic :: Scientific/Engineering', - 'Topic :: Scientific/Engineering :: Artificial Intelligence', - 'Topic :: Scientific/Engineering :: Physics', - 'License :: Other/Proprietary License ', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3 :: Only' - ], - keywords=['prognostics', 'diagnostics', 'fault detection', 'fdir', 'physics modeling', 'prognostics and health management', 'PHM', 'health management', 'surrogate modeling', 'model tuning', 'simulation', 'ivhm'], - package_dir={"": "src"}, - packages=find_packages(where='src'), - python_requires='>=3.7, <3.12', - install_requires=INSTALL_REQS, - license='NOSA', - project_urls={ # Optional - 'Bug Reports': 'https://github.com/nasa/progpy/issues', - 'Docs': 'https://nasa.github.io/progpy/', - 'Organization': 'https://www.nasa.gov/content/diagnostics-prognostics', - 'Source': 'https://github.com/nasa/progpy', - }, -) diff --git a/src/progpy/data_models/lstm_model.py b/src/progpy/data_models/lstm_model.py index 0449ad4a..a4d143f0 100644 --- a/src/progpy/data_models/lstm_model.py +++ b/src/progpy/data_models/lstm_model.py @@ -2,6 +2,7 @@ # National Aeronautics and Space Administration. All Rights Reserved. from collections import abc +import importlib.util from itertools import chain import matplotlib.pyplot as plt from numbers import Number @@ -23,6 +24,15 @@ class LSTMStateTransitionModel(DataModel): Most users will use the :py:func:`LSTMStateTransitionModel.from_data` method to create a model, but the model can be created by passing in a model directly into the constructor. The LSTM model in this method maps from [u_t-n+1, z_t-n, ..., u_t, z_t-1] to z_t. Past :term:`input` are stored in the :term:`model` internal :term:`state`. Actual calculation of :term:`output` is performed when :py:func:`LSTMStateTransitionModel.output` is called. When using in simulation that may not be until the simulation results are accessed. + .. note:: + ProgPy must be installed with [datadriven] option to use LSTM model. either + + pip3 install progpy[datadriven] + + or (if using local version) + + pip3 install '.[datadriven]' + Args: output_model (keras.Model): If a state model is present, maps from the state_model outputs to model :term:`output`. Otherwise, maps from model inputs to model :term:`output` state_model (keras.Model, optional): Keras model to use for state transition @@ -528,7 +538,10 @@ def from_data(cls, inputs, outputs, event_states=None, t_met=None, **kwargs): params['normalization'] = (z_mean, z_std) # Tensorflow is imported here to avoid importing it if not needed - from tensorflow import keras + try: + from tensorflow import keras + except ImportError as e: + raise ImportError("Missing required dependencies for data-driven model. ProgPy was imported directly. Instead import with datadriven dependencies using pip3 install progpy[datadriven] or pip3 install -e '.[datadriven]' (if installing from local copy)") # Build model callbacks = [ ]