Skip to content

Commit

Permalink
Merge pull request #56 from awoimbee/aw/update-version-requirements
Browse files Browse the repository at this point in the history
Update version requirements
  • Loading branch information
codie3611 authored Apr 15, 2024
2 parents 66cacf9 + 5cdd16c commit aacb322
Show file tree
Hide file tree
Showing 11 changed files with 751 additions and 820 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ jobs:
runs-on: ubuntu-latest

strategy:
# If either the tests for 3.8 or 3.11 fail all workflows
# are terminated to safe computing resources.
# If either the tests for 3.9 or 3.12 fail, all workflows
# are terminated to save computing resources.
fail-fast: true
# To safe runtime least and latest version supported are
# chosen. We go for 3.8 due to some dependencies. For more
# info see the pyproject.toml
# chosen. For more info see the pyproject.toml
matrix:
python-version: ["3.8", "3.11"]
python-version: ["3.9", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
19 changes: 1 addition & 18 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,7 @@ tasks:
desc: Lints the code and reports on issues.
cmds:
- poetry run black --check lasso
# E501:
# We disable too long lines in ArrayType since the docstrings for arrays
# must be behind the arrays for sphinx, thus lines cannot be shortened.
# Anyhow if you find any way to change feel free to submit a PR.
# E203:
# We ignore E203 since allowing whitespace around ':' makes slicing
# more understandable when doing complex slicing.
# W503:
# Allowing operators such as '+' after a new line instead of putting it
# on the previous one, complex condition chains are more understandable.
- |
poetry run flake8 lasso \
--ignore="E203,W503" \
--per-file-ignores="lasso/dyna/ArrayType.py:E501" \
--show-source \
--statistics \
--count
- poetry run pylint lasso
- poetry run ruff check

build:
desc: Builds the python package
Expand Down
28 changes: 16 additions & 12 deletions lasso/dimred/dimred_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ def __init__(
self.logfile_filepath = (
logfile_filepath
if logfile_filepath
else os.path.join(project_dir, "logfile")
if project_dir
else ""
else os.path.join(project_dir, "logfile") if project_dir else ""
)

self._msg_option = "{:16s}: {}"
Expand Down Expand Up @@ -864,9 +862,11 @@ def dimension_reduction_svd(self):
beta_group = self.h5file.create_group(HDF5FileNames.BETAS_GROUP_NAME.value)

excluded_entries = [
os.path.basename(os.path.split(entry)[0])
if self.use_folder_name
else os.path.basename(entry)
(
os.path.basename(os.path.split(entry)[0])
if self.use_folder_name
else os.path.basename(entry)
)
for entry in self.exclude_runs
]

Expand Down Expand Up @@ -953,9 +953,11 @@ def clustering_results(self):
# performs clustering with provided arguments

excluded_entries = [
os.path.basename(os.path.split(entry)[0])
if self.use_folder_name
else os.path.basename(entry)
(
os.path.basename(os.path.split(entry)[0])
if self.use_folder_name
else os.path.basename(entry)
)
for entry in self.exclude_runs
]

Expand Down Expand Up @@ -1020,9 +1022,11 @@ def visualize_results(self):
mark_outliers = False

excluded_entries = [
os.path.basename(os.path.split(entry)[0])
if self.use_folder_name
else os.path.basename(entry)
(
os.path.basename(os.path.split(entry)[0])
if self.use_folder_name
else os.path.basename(entry)
)
for entry in self.exclude_runs
]

Expand Down
50 changes: 25 additions & 25 deletions lasso/dyna/d3plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2412,12 +2412,10 @@ def _read_geometry_data(self):
if self.header.has_solid_2_extra_nodes:
section_word_length = 2 * n_solids
try:
self.arrays[
ArrayType.element_solid_extra_nodes
] = elem_solid_data = self._buffer.read_ndarray(
position, section_word_length * self.header.wordsize, 1, self._header.itype
).reshape(
(n_solids, 2)
self.arrays[ArrayType.element_solid_extra_nodes] = elem_solid_data = (
self._buffer.read_ndarray(
position, section_word_length * self.header.wordsize, 1, self._header.itype
).reshape((n_solids, 2))
)
except Exception:
trb_msg = traceback.format_exc()
Expand Down Expand Up @@ -2773,9 +2771,9 @@ def _read_rigid_body_description(self):
rigid_body_n_active_nodes, dtype=self._header.itype
)
self.arrays[ArrayType.rigid_body_node_indexes_list] = rigid_body_node_indexes_list
self.arrays[
ArrayType.rigid_body_active_node_indexes_list
] = rigid_body_active_node_indexes_list
self.arrays[ArrayType.rigid_body_active_node_indexes_list] = (
rigid_body_active_node_indexes_list
)

# update position
self.geometry_section_size = position
Expand Down Expand Up @@ -3451,9 +3449,11 @@ def _read_states_allocate_arrays(
ArrayType.rigid_wall_force: [n_states, n_rigid_walls],
ArrayType.rigid_wall_position: [n_states, n_rigid_walls, 3],
# nodes
ArrayType.node_temperature: [n_states, n_nodes, 3]
if header.has_node_temperature_layers
else [n_states, n_nodes],
ArrayType.node_temperature: (
[n_states, n_nodes, 3]
if header.has_node_temperature_layers
else [n_states, n_nodes]
),
ArrayType.node_heat_flux: [n_states, n_nodes, 3],
ArrayType.node_mass_scaling: [n_states, n_nodes],
ArrayType.node_displacement: [n_states, n_nodes, n_dim],
Expand Down Expand Up @@ -4532,10 +4532,10 @@ def _read_states_tshell(self, state_data: np.ndarray, var_index: int, array_dict
# PSTRAIN
if has_pstrain:
try:
array_dict[
ArrayType.element_tshell_effective_plastic_strain
] = tshell_layer_data[:, :, :, i_tshell_layer_var].reshape(
(n_states, n_tshells, n_layers)
array_dict[ArrayType.element_tshell_effective_plastic_strain] = (
tshell_layer_data[:, :, :, i_tshell_layer_var].reshape(
(n_states, n_tshells, n_layers)
)
)
except Exception:
trb_msg = traceback.format_exc()
Expand Down Expand Up @@ -4922,9 +4922,9 @@ def _read_states_shell(self, state_data: np.ndarray, var_index: int, array_dict:
pstrain_tensor = shell_nonlayer_data[
:, :, nonlayer_var_index : nonlayer_var_index + n_plastic_strain_tensor
]
array_dict[
ArrayType.element_shell_plastic_strain_tensor
] = pstrain_tensor.reshape((n_states, n_shells, n_layers, 6))
array_dict[ArrayType.element_shell_plastic_strain_tensor] = (
pstrain_tensor.reshape((n_states, n_shells, n_layers, 6))
)
except Exception:
trb_msg = traceback.format_exc()
msg = "A failure in %s was caught:\n%s"
Expand All @@ -4940,9 +4940,9 @@ def _read_states_shell(self, state_data: np.ndarray, var_index: int, array_dict:
thermal_tensor = shell_nonlayer_data[
:, :, nonlayer_var_index : nonlayer_var_index + n_thermal_strain_tensor
]
array_dict[
ArrayType.element_shell_thermal_strain_tensor
] = thermal_tensor.reshape((n_states, n_shells, 6))
array_dict[ArrayType.element_shell_thermal_strain_tensor] = (
thermal_tensor.reshape((n_states, n_shells, 6))
)
except Exception:
trb_msg = traceback.format_exc()
msg = "A failure in %s was caught:\n%s"
Expand Down Expand Up @@ -5432,9 +5432,9 @@ def get_dtype(type_flag):
# particle segment distance
elif var_name.startswith("NS dist"):
try:
array_dict[
ArrayType.airbag_particle_nearest_segment_distance
] = particle_data[:, :, i_particle_var].view(get_dtype(var_type))
array_dict[ArrayType.airbag_particle_nearest_segment_distance] = (
particle_data[:, :, i_particle_var].view(get_dtype(var_type))
)
except Exception:
trb_msg = traceback.format_exc()
msg = "A failure in %s %s was caught:\n%s"
Expand Down
6 changes: 0 additions & 6 deletions lasso/dyna/femzip_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,6 @@
(FemzipArrayType.STRAIN_XY, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
(FemzipArrayType.STRAIN_YZ, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
(FemzipArrayType.STRAIN_XZ, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
(FemzipArrayType.STRAIN_X, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
(FemzipArrayType.STRAIN_Y, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
(FemzipArrayType.STRAIN_Z, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
(FemzipArrayType.STRAIN_XY, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
(FemzipArrayType.STRAIN_YZ, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
(FemzipArrayType.STRAIN_XZ, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
# AIRBAG
(FemzipArrayType.AIRBAG_STATE_GEOM, FemzipVariableCategory.CPM_AIRBAG): {
ArrayType.airbag_n_active_particles,
Expand Down
10 changes: 5 additions & 5 deletions lasso/dyna/lsda_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def writecd(self, dir):
length = self.lengthsize + self.commandsize + len(dir)
s = struct.pack(self.lcunpack, length, Lsda.CD)
self.fp.write(s)
if type(dir) is str:
if isinstance(dir, str):
self.fp.write(bytes(dir, "utf-8"))
else:
self.fp.write(dir)
Expand All @@ -118,7 +118,7 @@ def writestentry(self, r):
)
s = struct.pack(self.lcunpack, length, Lsda.VARIABLE)
self.fp.write(s)
if type(r.name) is str:
if isinstance(r.name, str):
self.fp.write(bytes(r.name, "utf-8"))
else:
self.fp.write(r.name)
Expand Down Expand Up @@ -353,7 +353,7 @@ def _writesymboltable(lsda, f):
cwd = None

# Write all records
for (s, path) in slist:
for s, path in slist:
if path != cwd:
cdcmd = _get_min_cd(cwd, path)
f.writecd(cdcmd)
Expand Down Expand Up @@ -525,7 +525,7 @@ def cd(self, path, create=2): # change CWD
self.cwd = self.root
# path = string.split(path,"/")
# print(type(path))
if type(path) is bytes:
if isinstance(path, bytes):
path = str(path, "utf-8").split("/")
else:
path = path.split("/")
Expand Down Expand Up @@ -635,7 +635,7 @@ def nextfile(self): # Open next file in sequence
types = [("b", 1), ("h", 2), ("i", 4), ("q", 8), ("f", 4), ("d", 8)]
x = 17
types_ok = 1
for (a, b) in types:
for a, b in types:
s = struct.pack(a, x)
if len(s) != b:
print("LSDA: initialization error")
Expand Down
48 changes: 24 additions & 24 deletions lasso/femzip/femzip_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,16 +1068,16 @@ def _decompose_read_variables_array(
(n_timesteps_read, file_metadata.number_of_nodes, 3)
)
var_pos += array_size
result_arrays[
(variable_index, variable_name, FemzipVariableCategory.NODE)
] = var_array
result_arrays[(variable_index, variable_name, FemzipVariableCategory.NODE)] = (
var_array
)
else:
array_size = file_metadata.number_of_nodes
var_array = all_vars_array[:, var_pos : var_pos + array_size]
var_pos += array_size
result_arrays[
(variable_index, variable_name, FemzipVariableCategory.NODE)
] = var_array
result_arrays[(variable_index, variable_name, FemzipVariableCategory.NODE)] = (
var_array
)

elif variable_category == FemzipVariableCategory.SHELL:
array_size = (
Expand All @@ -1086,44 +1086,44 @@ def _decompose_read_variables_array(
)
var_array = all_vars_array[:, var_pos : var_pos + array_size]
var_pos += array_size
result_arrays[
(variable_index, variable_name, FemzipVariableCategory.SHELL)
] = var_array
result_arrays[(variable_index, variable_name, FemzipVariableCategory.SHELL)] = (
var_array
)
elif variable_category == FemzipVariableCategory.SOLID:
array_size = file_metadata.number_of_solid_elements
var_array = all_vars_array[:, var_pos : var_pos + array_size]
var_pos += array_size
result_arrays[
(variable_index, variable_name, FemzipVariableCategory.SOLID)
] = var_array
result_arrays[(variable_index, variable_name, FemzipVariableCategory.SOLID)] = (
var_array
)
elif variable_category == FemzipVariableCategory.BEAM:
array_size = file_metadata.number_of_1D_elements
var_array = all_vars_array[:, var_pos : var_pos + array_size]
var_pos += array_size
result_arrays[
variable_index, variable_name, FemzipVariableCategory.BEAM
] = var_array
result_arrays[variable_index, variable_name, FemzipVariableCategory.BEAM] = (
var_array
)
elif variable_category == FemzipVariableCategory.THICK_SHELL:
array_size = file_metadata.number_of_thick_shell_elements
var_array = all_vars_array[:, var_pos : var_pos + array_size]
var_pos += array_size
result_arrays[
variable_index, variable_name, FemzipVariableCategory.THICK_SHELL
] = var_array
result_arrays[variable_index, variable_name, FemzipVariableCategory.THICK_SHELL] = (
var_array
)
elif variable_category == FemzipVariableCategory.GLOBAL:
array_size = 6
var_array = all_vars_array[:, var_pos : var_pos + array_size]
var_pos += array_size
result_arrays[
variable_index, variable_name, FemzipVariableCategory.GLOBAL
] = var_array
result_arrays[variable_index, variable_name, FemzipVariableCategory.GLOBAL] = (
var_array
)
elif variable_category == FemzipVariableCategory.PART:
array_size = n_parts * 7 + n_rigid_walls * n_rigid_wall_vars
var_array = all_vars_array[:, var_pos : var_pos + array_size]
var_pos += array_size
result_arrays[
variable_index, variable_name, FemzipVariableCategory.PART
] = var_array
result_arrays[variable_index, variable_name, FemzipVariableCategory.PART] = (
var_array
)
elif variable_category == FemzipVariableCategory.CPM_FLOAT_VAR:
array_size = n_airbag_particles
var_array = all_vars_array[:, var_pos : var_pos + array_size]
Expand Down
4 changes: 1 addition & 3 deletions lasso/math/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def unique_subsamples(start: int, end: int, n_samples: int, seed=None) -> np.nda
"""
assert start <= end

if end - start < n_samples:
n_samples = end - start

n_samples = min(n_samples, end - start)
random.seed(seed)
indexes = np.array(random.sample(range(start, end), n_samples), dtype=np.int64)
random.seed()
Expand Down
1 change: 0 additions & 1 deletion lasso/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def custom_dir(custom_c, add):


class GetAttr:

"""
Base class for attr accesses in `self._xtra` passed down to `self.default
"""
Expand Down
Loading

0 comments on commit aacb322

Please sign in to comment.