Skip to content

Commit

Permalink
Revert "increased flake8 complexity"
Browse files Browse the repository at this point in the history
This reverts commit 3cf0de9.
  • Loading branch information
pjflux2001 committed Oct 14, 2023
1 parent d4b1176 commit e8db37c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 87 deletions.
11 changes: 2 additions & 9 deletions src/polyphy/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ def edit_data(self, edit_index: PPTypes.INT_CPU,
def store_fit(self):
pass

def __init__(self,
rng,
kernels,
ppConfig):
def __init__(self, rng, kernels, ppConfig):
pass


Expand All @@ -187,11 +184,7 @@ def __drawGUI__(self,
ppConfig):
pass

def __init__(self,
ppInternalData,
ppConfig,
batch_mode,
num_iterations):
def __init__(self, ppInternalData, ppConfig, batch_mode, num_iterations):
pass


Expand Down
125 changes: 48 additions & 77 deletions src/polyphy/core/discrete2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def register_data(self, ppData):
)
self.DOMAIN_SIZE_MAX = np.max([ppData.DOMAIN_SIZE[0], ppData.DOMAIN_SIZE[1]])
self.TRACE_RESOLUTION = PPTypes.INT_CPU(
(
PPTypes.FLOAT_CPU(self.TRACE_RESOLUTION_MAX) * ppData.DOMAIN_SIZE[0] /
self.DOMAIN_SIZE_MAX,
PPTypes.FLOAT_CPU(self.TRACE_RESOLUTION_MAX) * ppData.DOMAIN_SIZE[1] /
self.DOMAIN_SIZE_MAX
)
(PPTypes.FLOAT_CPU(self.TRACE_RESOLUTION_MAX) * ppData.DOMAIN_SIZE[0] /
self.DOMAIN_SIZE_MAX, PPTypes.FLOAT_CPU(
self.TRACE_RESOLUTION_MAX) * ppData.DOMAIN_SIZE[1] /
self.DOMAIN_SIZE_MAX)
)
self.DEPOSIT_RESOLUTION = (
self.TRACE_RESOLUTION[0] //
Expand Down Expand Up @@ -80,14 +78,12 @@ def __generate_test_data__(self, rng):
self.DOMAIN_MIN = (0.0, 0.0)
self.DOMAIN_MAX = (PPConfig.DOMAIN_SIZE_DEFAULT, PPConfig.DOMAIN_SIZE_DEFAULT)
self.data = np.zeros(shape=(self.N_DATA, 3), dtype=PPTypes.FLOAT_CPU)
self.data[:, 0] = rng.normal(
loc=self.DOMAIN_MIN[0] + 0.5 *
self.DOMAIN_MAX[0], scale=0.13 *
self.DOMAIN_SIZE[0], size=self.N_DATA)
self.data[:, 1] = rng.normal(
loc=self.DOMAIN_MIN[1] + 0.5 *
self.DOMAIN_MAX[1], scale=0.13 *
self.DOMAIN_SIZE[1], size=self.N_DATA)
self.data[:, 0] = rng.normal(loc=self.DOMAIN_MIN[0] + 0.5 *
self.DOMAIN_MAX[0], scale=0.13 *
self.DOMAIN_SIZE[0], size=self.N_DATA)
self.data[:, 1] = rng.normal(loc=self.DOMAIN_MIN[1] + 0.5 *
self.DOMAIN_MAX[1], scale=0.13 *
self.DOMAIN_SIZE[1], size=self.N_DATA)
self.data[:, 2] = np.mean(self.data[:, 2])


Expand All @@ -104,12 +100,10 @@ def __init_internal_data__(self, ppKernels):
# This can be very costly for many data points! (eg 10^5 or more)
def edit_data(self, edit_index: PPTypes.INT_CPU,
window: ti.ui.Window) -> PPTypes.INT_CPU:
mouse_rel_pos = (
np.min([np.max([0.001, window.get_cursor_pos()[0]]), 0.999]),
np.min([np.max([0.001, window.get_cursor_pos()[1]]), 0.999]))
mouse_pos = np.add(
self.ppConfig.ppData.DOMAIN_MIN,
np.multiply(mouse_rel_pos, self.ppConfig.ppData.DOMAIN_SIZE))
mouse_rel_pos = (np.min([np.max([0.001, window.get_cursor_pos()[0]]), 0.999]),
np.min([np.max([0.001, window.get_cursor_pos()[1]]), 0.999]))
mouse_pos = np.add(self.ppConfig.ppData.DOMAIN_MIN,
np.multiply(mouse_rel_pos, self.ppConfig.ppData.DOMAIN_SIZE))
self.ppConfig.ppData.data[edit_index, :] = (
mouse_pos[0], mouse_pos[1], self.ppConfig.ppData.AVG_WEIGHT
)
Expand All @@ -134,53 +128,37 @@ def store_fit(self):
def __init__(self, rng, ppKernels, ppConfig):
self.agents = np.zeros(
shape=(ppConfig.ppData.N_AGENTS, 4), dtype=PPTypes.FLOAT_CPU)
self.agents[:, 0] = rng.uniform(
low=ppConfig.ppData.DOMAIN_MIN[0] + 0.001,
high=ppConfig.ppData.DOMAIN_MAX[0] - 0.001,
size=ppConfig.ppData.N_AGENTS)
self.agents[:, 1] = rng.uniform(
low=ppConfig.ppData.DOMAIN_MIN[1] + 0.001,
high=ppConfig.ppData.DOMAIN_MAX[1] - 0.001,
size=ppConfig.ppData.N_AGENTS)
self.agents[:, 2] = rng.uniform(
low=0.0,
high=2.0 * np.pi,
size=ppConfig.ppData.N_AGENTS)
self.agents[:, 0] = rng.uniform(low=ppConfig.ppData.DOMAIN_MIN[0] + 0.001,
high=ppConfig.ppData.DOMAIN_MAX[0] - 0.001,
size=ppConfig.ppData.N_AGENTS)
self.agents[:, 1] = rng.uniform(low=ppConfig.ppData.DOMAIN_MIN[1] + 0.001,
high=ppConfig.ppData.DOMAIN_MAX[1] - 0.001,
size=ppConfig.ppData.N_AGENTS)
self.agents[:, 2] = rng.uniform(low=0.0, high=2.0 * np.pi,
size=ppConfig.ppData.N_AGENTS)
self.agents[:, 3] = 1.0
Logger.logToStdOut("info", 'Agent sample:', self.agents[0, :])

self.data_field = ti.Vector.field(
n=3,
dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.ppData.N_DATA)
self.agents_field = ti.Vector.field(
n=4,
dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.ppData.N_AGENTS)
self.deposit_field = ti.Vector.field(
n=2,
dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.DEPOSIT_RESOLUTION)
self.trace_field = ti.Vector.field(
n=1,
dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.TRACE_RESOLUTION)
self.vis_field = ti.Vector.field(
n=3,
dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.VIS_RESOLUTION)
Logger.logToStdOut(
"info",
'Total GPU memory allocated:',
PPTypes.INT_CPU(4 * (self.data_field.shape[0] * 3 +
self.agents_field.shape[0] * 4 +
self.deposit_field.shape[0] *
self.deposit_field.shape[1] * 2 +
self.trace_field.shape[0] *
self.trace_field.shape[1] * 1 +
self.vis_field.shape[0] *
self.vis_field.shape[1] * 3
) / 2 ** 20), 'MB')
self.data_field = ti.Vector.field(n=3, dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.ppData.N_DATA)
self.agents_field = ti.Vector.field(n=4, dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.ppData.N_AGENTS)
self.deposit_field = ti.Vector.field(n=2, dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.DEPOSIT_RESOLUTION)
self.trace_field = ti.Vector.field(n=1, dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.TRACE_RESOLUTION)
self.vis_field = ti.Vector.field(n=3, dtype=PPTypes.FLOAT_GPU,
shape=ppConfig.VIS_RESOLUTION)
Logger.logToStdOut("info", 'Total GPU memory allocated:',
PPTypes.INT_CPU(4 * (self.data_field.shape[0] * 3 +
self.agents_field.shape[0] * 4 +
self.deposit_field.shape[0] *
self.deposit_field.shape[1] * 2 +
self.trace_field.shape[0] *
self.trace_field.shape[1] * 1 +
self.vis_field.shape[0] *
self.vis_field.shape[1] * 3
) / 2 ** 20), 'MB')

self.ppConfig = ppConfig
self.ppKernels = ppKernels
Expand All @@ -191,11 +169,7 @@ class PPSimulation_2DDiscrete(PPSimulation):
def __drawGUI__(self, window, ppConfig):
GuiHelper.draw(self, window, ppConfig)

def __init__(self,
ppInternalData,
ppConfig,
batch_mode=False,
num_iterations=-1):
def __init__(self, ppInternalData, ppConfig, batch_mode=False, num_iterations=-1):
self.current_deposit_index = 0
self.data_edit_index = 0

Expand All @@ -208,10 +182,9 @@ def __init__(self,
# Check if file exists
if not os.path.exists("/tmp/flag"):
if batch_mode is False:
window = ti.ui.Window(
'PolyPhy',
(ppInternalData.vis_field.shape[0],
ppInternalData.vis_field.shape[1]), show_window=True)
window = ti.ui.Window('PolyPhy', (ppInternalData.vis_field.shape[0],
ppInternalData.vis_field.shape[1]
), show_window=True)
window.show()
canvas = window.get_canvas()

Expand All @@ -224,10 +197,8 @@ def __init__(self,
if curr_iteration > num_iterations:
break
if (num_iterations % curr_iteration) == 0:
Logger.logToStdOut(
"info",
'Running MCPM... iteration',
curr_iteration, '/', num_iterations)
Logger.logToStdOut("info", 'Running MCPM... iteration',
curr_iteration, '/', num_iterations)
else:
# batch_mode is False
# Handle controls
Expand Down
3 changes: 2 additions & 1 deletion src/polyphy/pipelines/discrete2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def __init__(self,
self.rng = default_rng()
self.ppInputData = PPInputData_2DDiscrete(self.ppConfig.input_file, self.rng)
self.ppConfig.register_data(self.ppInputData)
ti.init(arch=ti.cpu if os.path.exists("/tmp/flag") else ti.gpu)
#ti.init(arch=ti.cpu if os.path.exists("/tmp/flag") else ti.gpu)
ti.init(arch=ti.cpu)
self.kernels = PPKernels_2DDiscrete()
self.ppInternalData = PPInternalData_2DDiscrete(
self.rng,
Expand Down

0 comments on commit e8db37c

Please sign in to comment.