Skip to content

Conversation

@MikeAndSpencer
Copy link
Collaborator

Description

battery_electrochem.py

  • Included numpy libraries for calculations in next_state and output (numpy log function allows vectorization vs math log function)
  • calculate qnBdot and qnSdot outside of return function for clarity
  • include atleast_1d in return statement for compatibility with vectorization changes in prog_algs

centrifugal_pump.py

  • same changes as battery_electrochem.py
  • line 183 created if else statement for Qleak (calculation doesn't change but it's included for vectorization)
  • Fixed dictionary orderings so that they consistent across all dictionaries (e.g., state dicts)

prognostics_model.py

  • return array of process noise and measurement noise if working with arrays
  • logic included to vectorize process noise if vectors are passed to the process noise function, otherwise applies scalar process noise

@MikeAndSpencer MikeAndSpencer changed the title Library vectorization and other minor changes. See PR documentation f… Library vectorization and other minor changes. Oct 18, 2021
@MikeAndSpencer MikeAndSpencer changed the title Library vectorization and other minor changes. Library vectorization and other minor supporting changes. Oct 18, 2021
@teubert teubert self-requested a review October 18, 2021 18:53
@teubert teubert added the enhancement New feature or request label Oct 18, 2021
@teubert
Copy link
Collaborator

teubert commented Oct 19, 2021

@MikeAndSpencer:

For some reason your change causes the state x['c'] on "test_base_models" to be returned as an ndarray after simulating (e.g., [-7.4]) even when states and inputs are all floats this is what's causing the tests to fail. I'm trying to figure out why that is before approving.

Also, I'm going to add a few tests of vectorization support.

@teubert
Copy link
Collaborator

teubert commented Oct 19, 2021

Another observation. With the vectorization and python's optimizations - if the states are passed in as arrays the original states are altered as well (they aren't copied).

e.g.,

x = {'a': array([1, 2, 3, 4])}
x_new = m.next_state(x, ...) # m adds 1 to x['a']
now both x['a'] and x_new['a'] == array([2, 3, 4,5]) 

This is ok, I just need to make sure it won't be confusing for users

@teubert
Copy link
Collaborator

teubert commented Oct 19, 2021

@MikeAndSpencer:

For some reason your change causes the state x['c'] on "test_base_models" to be returned as an ndarray after simulating (e.g., [-7.4]) even when states and inputs are all floats this is what's causing the tests to fail. I'm trying to figure out why that is before approving.

Also, I'm going to add a few tests of vectorization support.

I understand now that this is what atleast_1d does. Question- is this strictly necessary, or can we remove it and have scalar input continue to return scalars. What do you think @MikeAndSpencer?

My concern is that this is a breaking change. Anyone who build off of this package expecting the return of next_state or output to be scalar when the input is will run into issues. If I was building this from scratch I would use this and say the return must be an array, but now there are users that have build on it. I would be interested in your thoughts

from math import asinh, log, inf
from math import inf
from copy import deepcopy
from numpy import maximum, minimum, sign, sqrt, array, ndarray, arcsinh, log, atleast_1d
Copy link
Collaborator

@teubert teubert Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from numpy import maximum, minimum, sign, sqrt, array, ndarray, arcsinh, log, atleast_1d
from numpy import arcsinh, log, atleast_1d

@teubert
Copy link
Collaborator

teubert commented Oct 19, 2021

I merged all my suggestions into a separate PR for your review. See #148

@lgtm-com
Copy link

lgtm-com bot commented Oct 22, 2021

This pull request introduces 1 alert when merging 11f5fba into ba40f0f - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times

@teubert teubert merged commit efdf8d5 into dev Oct 22, 2021
@lgtm-com
Copy link

lgtm-com bot commented Oct 22, 2021

This pull request introduces 1 alert when merging e782de9 into ba40f0f - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times

@teubert teubert deleted the ng_to_nasa branch October 28, 2021 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants