Skip to content
Rodd Talebi edited this page May 22, 2020 · 11 revisions

Notes to self:

PEP 8 guide

  • classes like CapCase
  • methods like lower_case

ABCs and Interface notes

Strongly Typed in Python3.6

Packages

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.

Ex:

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()

Variable Name Conventions

Classes:

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

Methods:

No capital letters and separated by underscores

Ex:

def get_fitness(indiv):
    pass

Variables:

No capital letters and separated by underscores

File Names:

No capital letters and separated by underscores

Dataset Language

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.

Start new py file

...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

logging

Order of levels:

  1. debug
  2. info
  3. warning
  4. error
  5. 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.