-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start work on Variables and Constraints
- Loading branch information
Showing
6 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
''' | ||
Chicory ML Workflow Manager | ||
Copyright (C) 2024 Alexis Maya-Isabelle Shuping | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
''' | ||
Chicory ML Workflow Manager | ||
Copyright (C) 2024 Alexis Maya-Isabelle Shuping | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
''' | ||
Chicory ML Workflow Manager | ||
Copyright (C) 2024 Alexis Maya-Isabelle Shuping | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
''' | ||
from modules.types.Option import Option, Nothing | ||
|
||
from typing import TypeVar | ||
from abc import ABC, abstractmethod | ||
|
||
A = TypeVar("A") | ||
|
||
class Variable[A](ABC): | ||
''' Stores a quantity whose value can vary from workflow to workflow, | ||
controlled either statically (manually set in configuration) or | ||
dynamically (controlled by an optimizer) | ||
''' | ||
@property | ||
@abstractmethod | ||
def is_bound(self) -> bool: | ||
''' `True` iff this variable has been bound to a value. | ||
Note that `Variable.val` will only return a value if the variable is | ||
bound; otherwise, a `TypeError` will be raised. | ||
''' | ||
... # pragma: no cover | ||
|
||
@property | ||
@abstractmethod | ||
def name(self) -> str: | ||
''' The name of this Variable. | ||
''' | ||
... # pragma: no cover | ||
|
||
@property | ||
@abstractmethod | ||
def desc(self) -> Option[str]: | ||
''' An optional long-form description for this Variable. | ||
''' | ||
... # pragma: no cover | ||
|
||
@property | ||
@abstractmethod | ||
def val(self) -> A: | ||
''' The bound value of this Variable. Only exists if `is_bound` is True; | ||
otherwise, a `TypeError` will be raised. | ||
''' | ||
... # pragma: no cover | ||
|
||
@property | ||
@abstractmethod | ||
def var_type(self) -> Option[type]: | ||
''' Optional type annotation for this Variable. | ||
''' | ||
... # pragma: no cover | ||
|
||
@property | ||
@abstractmethod | ||
def default(self) -> Option[A]: | ||
''' Optional default value for this Variable. | ||
''' | ||
... # pragma: no cover | ||
|
||
@abstractmethod | ||
def bind(self, val: A) -> 'BoundVariable[A]': | ||
''' Bind a value to this Variable. | ||
This only works for unbound Variables; otherwise, a TypeError will | ||
be raised. | ||
''' | ||
... # pragma: no cover | ||
|
||
class BoundVariable[A](Variable): | ||
''' A Variable that has already been given a value. | ||
''' | ||
def __init__(self, name: str, val: A, var_type: Option[type] = Nothing(), desc: Option[str] = Nothing(), default: Option[A] = Nothing()): | ||
self.__name = name | ||
self.__val = val | ||
self.__type = var_type | ||
self.__desc = desc | ||
self.__default = default | ||
|
||
@property | ||
def is_bound(self) -> bool: | ||
return True | ||
|
||
@property | ||
def name(self) -> str: | ||
return self.__name | ||
|
||
@property | ||
def desc(self) -> Option[str]: | ||
return self.__desc | ||
|
||
@property | ||
def val(self) -> A: | ||
return self.__val | ||
|
||
@property | ||
def var_type(self) -> Option[type]: | ||
return self.__type | ||
|
||
@property | ||
def default(self) -> Option[A]: | ||
return self.__default | ||
|
||
|
||
class UnboundVariable[A](Variable): | ||
''' A Variable which has not yet been given a value. | ||
''' | ||
def __init__(self, name: str, var_type: Option[type], desc: Option[str] = Nothing(), default: Option[A] = Nothing()): | ||
self.__name = name | ||
self.__type = var_type | ||
self.__desc = desc | ||
self.__default = default | ||
|
||
@property | ||
def is_bound(self) -> bool: | ||
return False | ||
|
||
@property | ||
def name(self) -> str: | ||
return self.__name | ||
|
||
@property | ||
def desc(self) -> Option[str]: | ||
return self.__desc | ||
|
||
@property | ||
def val(self) -> A: | ||
raise TypeError("Tried to access `val` on an unbound variable!") | ||
|
||
@property | ||
def var_type(self) -> Option[type]: | ||
return self.__type | ||
|
||
@property | ||
def default(self) -> Option[A]: | ||
return self.__default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
''' | ||
Chicory ML Workflow Manager | ||
Copyright (C) 2024 Alexis Maya-Isabelle Shuping | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
''' | ||
|
||
from enum import Enum | ||
|
||
class Strategy(Enum): | ||
''' Enumeration containing strategies for handling constraint failures. | ||
''' | ||
# Fail immediately if the Constraint is not met | ||
FAIL = 1 | ||
|
||
# If the Constraint is not met, clamp the failing value to the nearest | ||
# acceptable one. | ||
CLAMP = 2 | ||
|
||
# If the Constraint is not met, set the failing value to a constant. | ||
SET = 3 | ||
|
||
|
||
class Constraint: | ||
''' Defines a constraint on the experiment. | ||
Constraints ensure that a value at a specific stage of the experiment is | ||
within acceptable parameters. They can also constrain pre-experiment | ||
operations such as I/O wiring - see `WiringConstraint` | ||
''' | ||
pass | ||
|
||
class RangeConstraint(Constraint): | ||
''' Constrains a value to be within a specified range. | ||
''' | ||
pass | ||
|
||
class EqualsConstraint(Constraint): | ||
''' Constrains a value to be equal to a specified constant | ||
''' | ||
pass | ||
|
||
class WiringConstraint(Constraint): | ||
''' Constrains the automatic wiring system. | ||
This can be used to override the default wiring for a specific Input or | ||
Variable. | ||
''' | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
''' | ||
Chicory ML Workflow Manager | ||
Copyright (C) 2024 Alexis Maya-Isabelle Shuping | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
''' | ||
Chicory ML Workflow Manager | ||
Copyright (C) 2024 Alexis Maya-Isabelle Shuping | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
''' |