Skip to content

Commit

Permalink
remove unit
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed May 9, 2024
1 parent f6f510b commit 4036523
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
### Upcoming

#### Enhancements
- Chart legend's will support more than 8 Pioreactors.
- UI chart legend's will support more than 8 Pioreactors.
- UI chart colors are consistent across charts in the Overview.
- reduce the number of pop-ups in the UI, so they'll be less distractions.
- UI performance improvements.
- Upgraded to React 18
- Removed unused dependencies
Expand All @@ -10,11 +12,12 @@
- Upgrade paho-mqtt to 2.0
- faster `pio kill`
- faster job start from UI
- reduce the number of pop-ups in the UI, so they'll be less distractions.
- more humane error messages.
- Pioreactor's chart colors are consistent across charts in the Overview.
- added `random()` to profile expressions. This returns a number between 0 and 1.
- added `unit()` to profile expressions. This returns the pioreactor unit name. Useful for `if` statements in the common block.
- updated temperature inference model
- added exponentiation `**` to profile expressions. Ex: `${{ pio1:growth_rate_calculating:growth_rate.growth_rate ** 0.5 }}`
- added `random()` to profile expressions. This returns a number between 0 and 1. Ex: `${{ 25 + 25 * random() }} `



#### Bug fixes
- fix `pio plugins` on workers
Expand Down
8 changes: 5 additions & 3 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None:
if experiment != assigned_experiment:
return
else:
assigned_experiment = whoami.UNIVERSAL_EXPERIMENT
assigned_experiment = None

payload = loads(msg.payload) if msg.payload else {"options": {}, "args": []}

Expand Down Expand Up @@ -708,13 +708,15 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None:

@staticmethod
def _job_options_and_args_to_shell_command(
job_name: str, experiment: str, args: list[str], options: dict[str, Any]
job_name: str, experiment: Optional[str], args: list[str], options: dict[str, Any]
) -> str:
core_command = ["pio", "run", job_name]

# job source could be experiment_profile, but defaults to user
# we actually can skip another API request by reusing the assigned experiment above...
env = f'JOB_SOURCE={quote(options.pop("job_source", "user"))} EXPERIMENT={quote(experiment)}'
env = f'JOB_SOURCE={quote(options.pop("job_source", "user"))}'
if experiment:
env += f" EXPERIMENT={quote(experiment)}"

list_of_options: list[str] = []
for option, value in options.items():
Expand Down
10 changes: 7 additions & 3 deletions pioreactor/experiment_profiles/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from .sly import Parser
from pioreactor.pubsub import subscribe
from pioreactor.whoami import get_assigned_experiment_name
from pioreactor.whoami import get_unit_name
from pioreactor.whoami import is_active


Expand Down Expand Up @@ -47,6 +46,7 @@ class ProfileLexer(Lexer):
MINUS,
TIMES,
DIVIDE,
EXPONENT,
LESS_THAN,
GREATER_THAN,
LESS_THAN_OR_EQUAL,
Expand All @@ -67,6 +67,7 @@ class ProfileLexer(Lexer):
NAME["not"] = NOT

# Arithmetic Operators
EXPONENT = r"\*\*" # Regular expression for exponentiation
PLUS = r"\+"
MINUS = r"-"
TIMES = r"\*"
Expand Down Expand Up @@ -95,6 +96,7 @@ class ProfileParser(Parser):
("right", UMINUS),
("left", PLUS, MINUS),
("left", TIMES, DIVIDE),
("right", EXPONENT),
)

@_("expr AND expr", "expr OR expr")
Expand All @@ -111,6 +113,10 @@ def expr(self, p):
elif p[0] == "-":
return -p.expr

@_("expr EXPONENT expr") # Add rule for exponentiation
def expr(self, p):
return p.expr0**p.expr1

@_("expr PLUS expr", "expr MINUS expr", "expr TIMES expr", "expr DIVIDE expr")
def expr(self, p):
if p[1] == "+":
Expand Down Expand Up @@ -152,8 +158,6 @@ def expr(self, p):
def expr(self, p):
if p.FUNCTION == "random()":
return random()
elif p.FUNCTION == "unit()":
return get_unit_name()

@_("NAME")
def expr(self, p):
Expand Down
10 changes: 6 additions & 4 deletions pioreactor/tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

from math import sqrt

import pytest
from msgspec.json import encode

Expand Down Expand Up @@ -112,17 +114,17 @@ def test_calculator():
assert parse_profile_expression("-1.5 * 2.0") == -3.0
assert parse_profile_expression("-1.5 * -2.0") == 3.0
assert parse_profile_expression("-1.5 / -2.0") == 0.75
assert parse_profile_expression("4 ** 0.5") == sqrt(4)
assert parse_profile_expression("1 ** 100.0") == 1.0
assert parse_profile_expression("2.5 ** 0.5") == sqrt(2.5)
assert parse_profile_expression("2 ** (2 + 2)") == 2 ** (2 + 2)
assert 0 <= parse_profile_expression("random()") <= 1.0
assert 25 <= parse_profile_expression("25 + (25 * random())") <= 50

with pytest.raises(ZeroDivisionError):
assert parse_profile_expression("-1.5 / 0") == 0.75


def test_unit_function():
assert parse_profile_expression(f"unit() == {unit}")


def test_mqtt_fetches_with_calculations():
experiment = "_testing_experiment"
publish(
Expand Down

0 comments on commit 4036523

Please sign in to comment.