Skip to content

Commit

Permalink
clean up some edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Nov 16, 2023
1 parent c40d2c6 commit a43acc0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
- The "Label" step in the New Experiment flow is skipped if there is only 1 active Pioreactor in the cluster.
- Silenced the "LED is locked" warning - now it's a DEBUG level message.
- Fixed bug that wasn't passing lists correctly in `TopicToParserToTable`
- Faster boot times
- Fixed a bug where a plugin would not be loaded if it's name collided with a module in the stdlib. For example, putting `test.py` in `.pioreactor/plugins` would not be loaded, since when we tried to import `test`, it would load the stdlib's `test`, not ours. This has been fixed.
- Faster boot times.
- Faster UI load times.
- Fixed a bug where a plugin would not be loaded if it's name collided with a module in the stdlib. For example, putting `test.py` in `.pioreactor/plugins` would not be loaded, since when we tried to import`test`, it would load the stdlib's `test`, not the local plugin. This has been fixed.
- Simplify some UI elements.
- Security improvements.

Expand Down
9 changes: 8 additions & 1 deletion pioreactor/actions/stirring_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def stirring_calibration(min_dc: int, max_dc: int) -> None:
logger.error("No RPMs were measured. Is the stirring spinning?")
return

if len(filtered_dcs) <= n_samples * 0.75:
# the above can fail if all measured rpms are 0
logger.warning(
"Not enough RPMs were measured. Is the stirring spinning and working correctly? Try changing your initial_duty_cycle."
)
return

# since in practice, we want a look up from RPM -> required DC, we
# set x=measure_rpms, y=dcs
(rpm_coef, rpm_coef_std), (intercept, intercept_std) = simple_linear_regression(
Expand All @@ -100,7 +107,7 @@ def stirring_calibration(min_dc: int, max_dc: int) -> None:
)
return

if intercept <= 0:
elif intercept <= 0:
logger.warning("Something went wrong - the intercept should be greater than 0.")
return

Expand Down
4 changes: 3 additions & 1 deletion pioreactor/background_jobs/stirring.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ def kick_stirring(self) -> None:
self.logger.debug("Kicking stirring")
self.set_duty_cycle(100)
sleep(0.20)
self.set_duty_cycle(1.01 * self._previous_duty_cycle)
self.set_duty_cycle(
max(1.01 * self._previous_duty_cycle, 60)
) # DC should never be above 60. We want to avoid the death spiral to 100%.

def kick_stirring_but_avoid_od_reading(self) -> None:
"""
Expand Down
8 changes: 6 additions & 2 deletions pioreactor/utils/math_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def residuals_of_simple_linear_regression(x: Sequence, y: Sequence, trimmed=Fals


def correlation(x: Sequence, y: Sequence) -> float:
from statistics import correlation
from statistics import correlation, StatisticsError

return correlation(x, y)
try:
return correlation(x, y)
except StatisticsError as e:
# Raising the original error with additional data
raise StatisticsError(f"{e}. x: {x}, y: {y}") from e

0 comments on commit a43acc0

Please sign in to comment.