Skip to content

Commit

Permalink
Merge pull request #154 from nasa/152-make-tensor-flow-optional
Browse files Browse the repository at this point in the history
152 make tensor flow optional
  • Loading branch information
teubert authored Aug 7, 2024
2 parents 1bc324f + c236657 commit f030eb8
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 .
Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/update-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand Down
68 changes: 68 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
62 changes: 0 additions & 62 deletions setup.py

This file was deleted.

15 changes: 14 additions & 1 deletion src/progpy/data_models/lstm_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = [ ]
Expand Down

0 comments on commit f030eb8

Please sign in to comment.