-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Notes to self:
PEP 8 guide
- classes like CapCase
- methods like lower_case
- http://masnun.rocks/2017/04/15/interfaces-in-python-protocols-and-abcs/
- https://www.godaddy.com/engineering/2018/12/20/python-metaclasses/
- http://www.voidspace.org.uk/python/articles/duck_typing.shtml
- https://medium.com/@ageitgey/learn-how-to-use-static-type-checking-in-python-3-6-in-10-minutes-12c86d72677b
- https://realpython.com/python-type-checking/
Going to try and do "absolute imports" with respect to the root directory where main.py exists, then also add sys.path of the root directory to each file so that the user can import individual files for their own testing without erroring or without having to run from the root directory.
Root -> ParentDir -> file1.py + ChildDir -> file2.py
in file1.py to import file2.py:
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from ParentDir.ChildDir import file2
file2.whatever()
Start with capital letters and camelcase. Abstract classes should not have underscores, and classes that inherit from an abstract class should be name stuch that it's AbstractClass_DescriptiveName()
Ex:
class BlockEvaluate_Abstract(ABC):
pass
class BlockEvaluate_TensorFlow(BlockEvaluate):
pass
No capital letters and separated by underscores
Ex:
def get_fitness(indiv):
pass
No capital letters and separated by underscores
No capital letters and separated by underscores
Training -> normal data used to train models
Validation -> used to fit hyperparameters; so in our case, used to set fitness if we have models to train (otherwise we only have trianing)
Testing -> the dataset external to the whole evolutionary process. Used to test final performance after all evolution done.
...based off the import rules mentioned earlier, going to adopt the following protocol
'''
root/parentdir/parentdir2/filename.py
Overview:
overview of what will/should be in this file and how it interacts with the rest of the code
Rules:
mention any assumptions made in the code or rules about code structure should go here
'''
### packages
import ...
### sys relative to root dir
import sys
from os.path import dirname, realpath
sys.path.append(dirname(dirname(dirname(realpath(__file__))))) #one 'dirname' for every parentdir including root
### absolute imports wrt root
from parentdir.file1 import method1
### rest of the code goes below
# use 3# for establishing sections into the code and 1# for general comments.
# include 2 empty lines between methods in a file
# include 3 empty lines between classes
def my_funct(pos_arg0, pos_arg1: dtype, kwd_arg0=None):
'''
input description + dtypes
output description + dtypes
description of func
'''
my_dict = {key0: val0}
my_var = value
if my_var >= other_value:
pass
Order of levels:
- debug
- info
- warning
- error
- critical
Note, each logging.DEBUG (or other level) actually returns a number like 10, 20, 30, 40, 50
Generally I'll try to add a logging.debug statement at the beginning of every function saying which method we're inside of and what the arguments are. If the method has to do with mating, mutating, evaluating (including setting active nodes and need_evaluate) are going to be upgraded from debug to logging.info.
Try to include the individual_material.id or the block_material.id if available...at the very least the block_definition.material if not associated with a block_material instance.