Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disabled E501 (line too long) check and reformatted py files #68

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ formats = bdist_wheel
[flake8]
# Some sane defaults for the code style checker flake8
max_line_length = 88
extend_ignore = E203, W503
extend_ignore = E203, W503, E501
# ^ Black-compatible
# E203 and W503 have edge cases handled by black
exclude =
Expand Down
3 changes: 1 addition & 2 deletions src/polyphy/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def set_precision(float_precision):
PPTypes.FLOAT_CPU = np.float16
PPTypes.FLOAT_GPU = ti.f16
else:
raise ValueError("Invalid float precision value. Supported values: \
float64, float32, float16")
raise ValueError("Invalid float precision value. Supported values: float64, float32, float16")


class PPConfig:
Expand Down
56 changes: 22 additions & 34 deletions src/polyphy/core/discrete2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ def register_data(self, ppData):
self.ppData = ppData
self.TRACE_RESOLUTION_MAX = 1440
self.DATA_TO_AGENTS_RATIO = (
PPTypes.FLOAT_CPU(ppData.N_DATA) /
PPTypes.FLOAT_CPU(ppData.N_AGENTS)
PPTypes.FLOAT_CPU(ppData.N_DATA) / PPTypes.FLOAT_CPU(ppData.N_AGENTS)
)
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)
)
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
))
self.DEPOSIT_RESOLUTION = (
self.TRACE_RESOLUTION[0] //
PPConfig.DEPOSIT_DOWNSCALING_FACTOR, self.TRACE_RESOLUTION[1] //
PPConfig.DEPOSIT_DOWNSCALING_FACTOR
self.TRACE_RESOLUTION[0] // PPConfig.DEPOSIT_DOWNSCALING_FACTOR,
self.TRACE_RESOLUTION[1] // PPConfig.DEPOSIT_DOWNSCALING_FACTOR
)

# Check if these are set and if not give them decent initial estimates
Expand Down Expand Up @@ -65,12 +61,10 @@ def __load_from_file__(self):
self.domain_min = (np.min(self.data[:, 0]), np.min(self.data[:, 1]))
self.domain_max = (np.max(self.data[:, 0]), np.max(self.data[:, 1]))
self.domain_size = np.subtract(self.domain_max, self.domain_min)
self.DOMAIN_MIN = (self.domain_min[0] - PPConfig.DOMAIN_MARGIN *
self.domain_size[0], self.domain_min[1] -
PPConfig.DOMAIN_MARGIN * self.domain_size[1])
self.DOMAIN_MAX = (self.domain_max[0] + PPConfig.DOMAIN_MARGIN *
self.domain_size[0], self.domain_max[1] +
PPConfig.DOMAIN_MARGIN * self.domain_size[1])
self.DOMAIN_MIN = (self.domain_min[0] - PPConfig.DOMAIN_MARGIN * self.domain_size[0],
self.domain_min[1] - PPConfig.DOMAIN_MARGIN * self.domain_size[1])
self.DOMAIN_MAX = (self.domain_max[0] + PPConfig.DOMAIN_MARGIN * self.domain_size[0],
self.domain_max[1] + PPConfig.DOMAIN_MARGIN * self.domain_size[1])
self.DOMAIN_SIZE = np.subtract(self.DOMAIN_MAX, self.DOMAIN_MIN)
self.AVG_WEIGHT = np.mean(self.data[:, 2])

Expand All @@ -83,12 +77,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 Down Expand Up @@ -139,7 +133,8 @@ def __init__(self, rng, ppKernels, ppConfig):
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,
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, :])
Expand All @@ -155,16 +150,9 @@ def __init__(self, rng, ppKernels, ppConfig):
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')

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
self.__init_internal_data__(ppKernels)
Expand Down
30 changes: 12 additions & 18 deletions src/polyphy/core/discrete3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ def register_data(self, ppData):
self.DOMAIN_SIZE_MAX = np.max(
[ppData.DOMAIN_SIZE[0], ppData.DOMAIN_SIZE[1], ppData.DOMAIN_SIZE[2]])
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[2] /
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,
PPTypes.FLOAT_CPU(self.TRACE_RESOLUTION_MAX) * ppData.DOMAIN_SIZE[2] / self.DOMAIN_SIZE_MAX))
self.DEPOSIT_RESOLUTION = (
self.TRACE_RESOLUTION[0] // PPConfig.DEPOSIT_DOWNSCALING_FACTOR,
self.TRACE_RESOLUTION[1] // PPConfig.DEPOSIT_DOWNSCALING_FACTOR,
Expand Down Expand Up @@ -138,12 +135,10 @@ def store_fit(self):
Logger.logToStdOut("info", 'Storing solution data in data/fits/')
deposit = self.deposit_field.to_numpy()
np.save(
self.ppConfig.ppData.ROOT + 'data/fits/deposit_' + current_stamp +
'.npy', deposit)
self.ppConfig.ppData.ROOT + 'data/fits/deposit_' + current_stamp + '.npy', deposit)
trace = self.trace_field.to_numpy()
np.save(
self.ppConfig.ppData.ROOT + 'data/fits/trace_' + current_stamp +
'.npy', trace)
self.ppConfig.ppData.ROOT + 'data/fits/trace_' + current_stamp + '.npy', trace)
return current_stamp, deposit, trace

def __init__(self, rng, ppKernels, ppConfig):
Expand Down Expand Up @@ -196,13 +191,8 @@ def __init__(self, rng, ppKernels, ppConfig):
Logger.logToStdOut(
"info",
'Total GPU memory allocated:', PPTypes.INT_CPU(
4 * (
self.data_field.shape[0] * 4 +
self.agents_field.shape[0] * 6 +
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')
4 * (self.data_field.shape[0] * 4 + self.agents_field.shape[0] * 6 + 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
self.__init_internal_data__(ppKernels)
Expand All @@ -212,7 +202,11 @@ class PPSimulation_3DDiscrete(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.do_export = False
self.do_screenshot = False
Expand Down
3 changes: 1 addition & 2 deletions src/polyphy/kernel/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def ray_AABB_intersection(self, ray_pos, ray_dir, AABB_min, AABB_max):
t5 = (AABB_max[2] - ray_pos[2]) / ray_dir[2]
t6 = ti.max(ti.max(ti.min(t0, t1), ti.min(t2, t3)), ti.min(t4, t5))
t7 = ti.min(ti.min(ti.max(t0, t1), ti.max(t2, t3)), ti.max(t4, t5))
return PPTypes.VEC2f(-1.0, -1.0) if (
t7 < 0.0 or t6 >= t7) else PPTypes.VEC2f(t6, t7)
return PPTypes.VEC2f(-1.0, -1.0) if (t7 < 0.0 or t6 >= t7) else PPTypes.VEC2f(t6, t7)

# GPU kernels (callable by core classes via Taichi API) ========================
@ti.kernel
Expand Down
Loading
Loading