Skip to content

Commit

Permalink
move reset logic to pytes fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Oct 5, 2023
1 parent 0048951 commit f8b89bf
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 91 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
- Fix an OD calibration bug that would produce an extremely high value when the signal was below the minimum signal (the blank) during OD calibration.
- IPv4 is really IPv4 now.
- Adding ability to install plugins by name via the UI.
- New tools to update Pioreactors on a local access point. Docs coming soon!
- New tools to update Pioreactors on a local access point. More docs coming soon!
- New `turbidostat_targeting_od` dosing automation. This is just like the existing `turbidostat`, but
targets the raw OD instead of normalized OD. This is most useful post-OD calibration.
- In the UI, the dosing automation "Turbidostat" has been renamed "Turbidostat Targeting nOD"


### 23.9.20
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/automations/dosing/turbidostat_targeting_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, target_od: float | str, volume: float | str, **kwargs) -> Non

def execute(self) -> Optional[events.DilutionEvent]:
if self.latest_od["2"] >= self.target_od:
latest_od_before_dosing = self.latest_od
latest_od_before_dosing = self.latest_od["2"]
target_od_before_dosing = self.target_od
results = self.execute_io_action(media_ml=self.volume, waste_ml=self.volume)
media_moved = results["media_ml"]
Expand Down
13 changes: 12 additions & 1 deletion pioreactor/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@


@pytest.fixture(autouse=True)
def run_around_tests():
def run_around_tests(request):
from pioreactor.utils import local_intermittent_storage
from pioreactor.utils import local_persistant_storage

test_name = request.node.name

with local_intermittent_storage("led_locks") as cache:
for key in cache.iterkeys():
del cache[key]
Expand All @@ -36,4 +38,13 @@ def run_around_tests():
for key in cache.iterkeys():
del cache[key]

with local_persistant_storage("media_throughput") as c:
c.pop(test_name)
with local_persistant_storage("alt_media_throughput") as c:
c.pop(test_name)
with local_persistant_storage("alt_media_fraction") as c:
c.pop(test_name)
with local_persistant_storage("vial_volume") as c:
c.pop(test_name)

yield
167 changes: 79 additions & 88 deletions pioreactor/tests/test_dosing_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from pioreactor.automations.dosing.pid_morbidostat import PIDMorbidostat
from pioreactor.automations.dosing.silent import Silent
from pioreactor.automations.dosing.turbidostat import Turbidostat
from pioreactor.automations.dosing.turbidostat_targeting_od import TurbidostatTargetingOD
from pioreactor.background_jobs.dosing_control import DosingController
from pioreactor.background_jobs.dosing_control import start_dosing_control
from pioreactor.structs import DosingEvent
Expand Down Expand Up @@ -207,6 +208,84 @@ def test_turbidostat_automation() -> None:
assert algo.run() is None


def test_turbidostat_targeting_od_automation() -> None:
experiment = "test_turbidostat_targeting_od_automation"

target_od = 0.2
with TurbidostatTargetingOD(
target_od=target_od,
duration=60,
volume=0.25,
unit=unit,
experiment=experiment,
skip_first_run=True,
) as algo:
pubsub.publish(
f"pioreactor/{unit}/{experiment}/od_reading/ods",
encode(
structs.ODReadings(
timestamp=current_utc_datetime(),
ods={
"2": structs.ODReading(
timestamp=current_utc_datetime(), angle="45", od=0.05, channel="2"
)
},
)
),
)
pause()

pubsub.publish(
f"pioreactor/{unit}/{experiment}/od_reading/ods",
encode(
structs.ODReadings(
timestamp=current_utc_datetime(),
ods={
"2": structs.ODReading(
timestamp=current_utc_datetime(), angle="45", od=0.250, channel="2"
)
},
)
),
)
pause()
assert isinstance(algo.run(), events.DilutionEvent)

pubsub.publish(
f"pioreactor/{unit}/{experiment}/od_reading/ods",
encode(
structs.ODReadings(
timestamp=current_utc_datetime(),
ods={
"2": structs.ODReading(
timestamp=current_utc_datetime(), angle="45", od=0.500, channel="2"
)
},
)
),
)
pause()
assert isinstance(algo.run(), events.DilutionEvent)

pubsub.publish(
f"pioreactor/{unit}/{experiment}/od_reading/ods",
encode(
structs.ODReadings(
timestamp=current_utc_datetime(),
ods={
"2": structs.ODReading(
timestamp=current_utc_datetime(), angle="45", od=0.100, channel="2"
)
},
)
),
)
pause()
assert algo.run() is None

assert algo.media_throughput == 0.50


def test_pid_morbidostat_automation() -> None:
experiment = "test_pid_morbidostat_automation"
target_growth_rate = 0.09
Expand Down Expand Up @@ -410,14 +489,6 @@ def test_old_readings_will_not_execute_io() -> None:

def test_throughput_calculator() -> None:
experiment = "test_throughput_calculator"
with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_fraction") as c:
c[experiment] = 0.0

with DosingController(
unit,
Expand Down Expand Up @@ -534,11 +605,6 @@ def test_throughput_calculator_manual_set() -> None:

def test_execute_io_action() -> None:
experiment = "test_execute_io_action"
with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_throughput") as c:
c[experiment] = 0.0

with DosingController(unit, experiment, "silent") as ca:
ca.automation_job.execute_io_action(media_ml=0.50, alt_media_ml=0.35, waste_ml=0.50 + 0.35)
Expand All @@ -564,14 +630,6 @@ def test_execute_io_action() -> None:

def test_execute_io_action2() -> None:
experiment = "test_execute_io_action2"
with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_fraction") as c:
c[experiment] = 0.0

with DosingController(unit, experiment, "silent", initial_vial_volume=14.0) as ca:
ca.automation_job.execute_io_action(media_ml=1.25, alt_media_ml=0.01, waste_ml=1.26)
Expand All @@ -584,14 +642,6 @@ def test_execute_io_action2() -> None:
def test_execute_io_action_outputs1() -> None:
# regression test
experiment = "test_execute_io_action_outputs1"
with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_fraction") as c:
c[experiment] = 0.0

with DosingAutomationJob(unit=unit, experiment=experiment) as ca:
result = ca.execute_io_action(media_ml=1.25, alt_media_ml=0.01, waste_ml=1.26)
Expand All @@ -602,14 +652,6 @@ def test_execute_io_action_outputs1() -> None:

def test_mqtt_properties_in_dosing_automations():
experiment = "test_mqtt_properties"
with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_fraction") as c:
c[experiment] = 0.0

with DosingAutomationJob(unit=unit, experiment=experiment) as ca:
r = pubsub.subscribe(
Expand Down Expand Up @@ -661,14 +703,6 @@ def test_execute_io_action_outputs_will_be_null_if_calibration_is_not_defined()
def test_execute_io_action_outputs_will_shortcut_if_disconnected() -> None:
# regression test
experiment = "test_execute_io_action_outputs_will_shortcut_if_disconnected"
with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_fraction") as c:
c[experiment] = 0.0

ca = DosingAutomationJob(unit=unit, experiment=experiment)
ca.clean_up()
Expand Down Expand Up @@ -872,14 +906,6 @@ def test_changing_algo_over_mqtt_when_it_fails_will_rollback() -> None:

def test_changing_algo_over_mqtt_will_not_produce_two_dosing_jobs() -> None:
experiment = "test_changing_algo_over_mqtt_will_not_produce_two_dosing_jobs"
with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_fraction") as c:
c[experiment] = 0.0

algo = DosingController(
unit,
Expand Down Expand Up @@ -935,8 +961,6 @@ def test_changing_algo_over_mqtt_will_not_produce_two_dosing_jobs() -> None:

def test_changing_algo_over_mqtt_with_wrong_type_is_okay() -> None:
experiment = "test_changing_algo_over_mqtt_with_wrong_type_is_okay"
with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

algo = DosingController(
unit,
Expand Down Expand Up @@ -1139,15 +1163,6 @@ def test_strings_are_okay_for_chemostat() -> None:
unit = get_unit_name()
experiment = "test_strings_are_okay_for_chemostat"

with local_persistant_storage("media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_throughput") as c:
c[experiment] = 0.0

with local_persistant_storage("alt_media_fraction") as c:
c[experiment] = 0.0

with start_dosing_control(
"chemostat", "20", False, unit, experiment, volume="0.7"
) as controller:
Expand Down Expand Up @@ -1183,15 +1198,6 @@ def test_pass_in_initial_alt_media_fraction() -> None:
experiment = "test_pass_in_initial_alt_media_fraction"
unit = get_unit_name()

with local_persistant_storage("alt_media_fraction") as c:
c.pop(experiment)

with local_persistant_storage("media_throughput") as c:
c.pop(experiment)

with local_persistant_storage("vial_volume") as c:
c.pop(experiment)

with start_dosing_control(
"chemostat", 20, False, unit, experiment, volume=0.25, initial_alt_media_fraction=0.5
) as controller:
Expand Down Expand Up @@ -1223,12 +1229,6 @@ def test_chemostat_from_0_volume() -> None:
experiment = "test_chemostat_from_0_volume"
unit = get_unit_name()

with local_persistant_storage("vial_volume") as c:
c.pop(experiment)

with local_persistant_storage("media_throughput") as c:
c.pop(experiment)

with start_dosing_control(
"chemostat",
0.25,
Expand All @@ -1252,15 +1252,6 @@ def test_execute_io_respects_dilutions_ratios() -> None:
unit = get_unit_name()
experiment = "test_execute_io_respects_dilutions_ratios"

with local_persistant_storage("alt_media_fraction") as c:
c.pop(experiment)

with local_persistant_storage("media_throughput") as c:
c.pop(experiment)

with local_persistant_storage("alt_media_throughput") as c:
c.pop(experiment)

class ChemostatAltMedia(DosingAutomationJob):
automation_name = "chemostat_alt_media"
published_settings = {
Expand Down

0 comments on commit f8b89bf

Please sign in to comment.