Skip to content

Commit aacb322

Browse files
authored
Merge pull request #56 from awoimbee/aw/update-version-requirements
Update version requirements
2 parents 66cacf9 + 5cdd16c commit aacb322

File tree

11 files changed

+751
-820
lines changed

11 files changed

+751
-820
lines changed

.github/workflows/ci-cd.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ jobs:
1212
runs-on: ubuntu-latest
1313

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

2423
steps:
2524
- uses: actions/checkout@v3

Taskfile.yml

+1-18
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,7 @@ tasks:
1010
desc: Lints the code and reports on issues.
1111
cmds:
1212
- poetry run black --check lasso
13-
# E501:
14-
# We disable too long lines in ArrayType since the docstrings for arrays
15-
# must be behind the arrays for sphinx, thus lines cannot be shortened.
16-
# Anyhow if you find any way to change feel free to submit a PR.
17-
# E203:
18-
# We ignore E203 since allowing whitespace around ':' makes slicing
19-
# more understandable when doing complex slicing.
20-
# W503:
21-
# Allowing operators such as '+' after a new line instead of putting it
22-
# on the previous one, complex condition chains are more understandable.
23-
- |
24-
poetry run flake8 lasso \
25-
--ignore="E203,W503" \
26-
--per-file-ignores="lasso/dyna/ArrayType.py:E501" \
27-
--show-source \
28-
--statistics \
29-
--count
30-
- poetry run pylint lasso
13+
- poetry run ruff check
3114

3215
build:
3316
desc: Builds the python package

lasso/dimred/dimred_run.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,7 @@ def __init__(
328328
self.logfile_filepath = (
329329
logfile_filepath
330330
if logfile_filepath
331-
else os.path.join(project_dir, "logfile")
332-
if project_dir
333-
else ""
331+
else os.path.join(project_dir, "logfile") if project_dir else ""
334332
)
335333

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

866864
excluded_entries = [
867-
os.path.basename(os.path.split(entry)[0])
868-
if self.use_folder_name
869-
else os.path.basename(entry)
865+
(
866+
os.path.basename(os.path.split(entry)[0])
867+
if self.use_folder_name
868+
else os.path.basename(entry)
869+
)
870870
for entry in self.exclude_runs
871871
]
872872

@@ -953,9 +953,11 @@ def clustering_results(self):
953953
# performs clustering with provided arguments
954954

955955
excluded_entries = [
956-
os.path.basename(os.path.split(entry)[0])
957-
if self.use_folder_name
958-
else os.path.basename(entry)
956+
(
957+
os.path.basename(os.path.split(entry)[0])
958+
if self.use_folder_name
959+
else os.path.basename(entry)
960+
)
959961
for entry in self.exclude_runs
960962
]
961963

@@ -1020,9 +1022,11 @@ def visualize_results(self):
10201022
mark_outliers = False
10211023

10221024
excluded_entries = [
1023-
os.path.basename(os.path.split(entry)[0])
1024-
if self.use_folder_name
1025-
else os.path.basename(entry)
1025+
(
1026+
os.path.basename(os.path.split(entry)[0])
1027+
if self.use_folder_name
1028+
else os.path.basename(entry)
1029+
)
10261030
for entry in self.exclude_runs
10271031
]
10281032

lasso/dyna/d3plot.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -2412,12 +2412,10 @@ def _read_geometry_data(self):
24122412
if self.header.has_solid_2_extra_nodes:
24132413
section_word_length = 2 * n_solids
24142414
try:
2415-
self.arrays[
2416-
ArrayType.element_solid_extra_nodes
2417-
] = elem_solid_data = self._buffer.read_ndarray(
2418-
position, section_word_length * self.header.wordsize, 1, self._header.itype
2419-
).reshape(
2420-
(n_solids, 2)
2415+
self.arrays[ArrayType.element_solid_extra_nodes] = elem_solid_data = (
2416+
self._buffer.read_ndarray(
2417+
position, section_word_length * self.header.wordsize, 1, self._header.itype
2418+
).reshape((n_solids, 2))
24212419
)
24222420
except Exception:
24232421
trb_msg = traceback.format_exc()
@@ -2773,9 +2771,9 @@ def _read_rigid_body_description(self):
27732771
rigid_body_n_active_nodes, dtype=self._header.itype
27742772
)
27752773
self.arrays[ArrayType.rigid_body_node_indexes_list] = rigid_body_node_indexes_list
2776-
self.arrays[
2777-
ArrayType.rigid_body_active_node_indexes_list
2778-
] = rigid_body_active_node_indexes_list
2774+
self.arrays[ArrayType.rigid_body_active_node_indexes_list] = (
2775+
rigid_body_active_node_indexes_list
2776+
)
27792777

27802778
# update position
27812779
self.geometry_section_size = position
@@ -3451,9 +3449,11 @@ def _read_states_allocate_arrays(
34513449
ArrayType.rigid_wall_force: [n_states, n_rigid_walls],
34523450
ArrayType.rigid_wall_position: [n_states, n_rigid_walls, 3],
34533451
# nodes
3454-
ArrayType.node_temperature: [n_states, n_nodes, 3]
3455-
if header.has_node_temperature_layers
3456-
else [n_states, n_nodes],
3452+
ArrayType.node_temperature: (
3453+
[n_states, n_nodes, 3]
3454+
if header.has_node_temperature_layers
3455+
else [n_states, n_nodes]
3456+
),
34573457
ArrayType.node_heat_flux: [n_states, n_nodes, 3],
34583458
ArrayType.node_mass_scaling: [n_states, n_nodes],
34593459
ArrayType.node_displacement: [n_states, n_nodes, n_dim],
@@ -4532,10 +4532,10 @@ def _read_states_tshell(self, state_data: np.ndarray, var_index: int, array_dict
45324532
# PSTRAIN
45334533
if has_pstrain:
45344534
try:
4535-
array_dict[
4536-
ArrayType.element_tshell_effective_plastic_strain
4537-
] = tshell_layer_data[:, :, :, i_tshell_layer_var].reshape(
4538-
(n_states, n_tshells, n_layers)
4535+
array_dict[ArrayType.element_tshell_effective_plastic_strain] = (
4536+
tshell_layer_data[:, :, :, i_tshell_layer_var].reshape(
4537+
(n_states, n_tshells, n_layers)
4538+
)
45394539
)
45404540
except Exception:
45414541
trb_msg = traceback.format_exc()
@@ -4922,9 +4922,9 @@ def _read_states_shell(self, state_data: np.ndarray, var_index: int, array_dict:
49224922
pstrain_tensor = shell_nonlayer_data[
49234923
:, :, nonlayer_var_index : nonlayer_var_index + n_plastic_strain_tensor
49244924
]
4925-
array_dict[
4926-
ArrayType.element_shell_plastic_strain_tensor
4927-
] = pstrain_tensor.reshape((n_states, n_shells, n_layers, 6))
4925+
array_dict[ArrayType.element_shell_plastic_strain_tensor] = (
4926+
pstrain_tensor.reshape((n_states, n_shells, n_layers, 6))
4927+
)
49284928
except Exception:
49294929
trb_msg = traceback.format_exc()
49304930
msg = "A failure in %s was caught:\n%s"
@@ -4940,9 +4940,9 @@ def _read_states_shell(self, state_data: np.ndarray, var_index: int, array_dict:
49404940
thermal_tensor = shell_nonlayer_data[
49414941
:, :, nonlayer_var_index : nonlayer_var_index + n_thermal_strain_tensor
49424942
]
4943-
array_dict[
4944-
ArrayType.element_shell_thermal_strain_tensor
4945-
] = thermal_tensor.reshape((n_states, n_shells, 6))
4943+
array_dict[ArrayType.element_shell_thermal_strain_tensor] = (
4944+
thermal_tensor.reshape((n_states, n_shells, 6))
4945+
)
49464946
except Exception:
49474947
trb_msg = traceback.format_exc()
49484948
msg = "A failure in %s was caught:\n%s"
@@ -5432,9 +5432,9 @@ def get_dtype(type_flag):
54325432
# particle segment distance
54335433
elif var_name.startswith("NS dist"):
54345434
try:
5435-
array_dict[
5436-
ArrayType.airbag_particle_nearest_segment_distance
5437-
] = particle_data[:, :, i_particle_var].view(get_dtype(var_type))
5435+
array_dict[ArrayType.airbag_particle_nearest_segment_distance] = (
5436+
particle_data[:, :, i_particle_var].view(get_dtype(var_type))
5437+
)
54385438
except Exception:
54395439
trb_msg = traceback.format_exc()
54405440
msg = "A failure in %s %s was caught:\n%s"

lasso/dyna/femzip_mapper.py

-6
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,6 @@
234234
(FemzipArrayType.STRAIN_XY, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
235235
(FemzipArrayType.STRAIN_YZ, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
236236
(FemzipArrayType.STRAIN_XZ, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
237-
(FemzipArrayType.STRAIN_X, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
238-
(FemzipArrayType.STRAIN_Y, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
239-
(FemzipArrayType.STRAIN_Z, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
240-
(FemzipArrayType.STRAIN_XY, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
241-
(FemzipArrayType.STRAIN_YZ, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
242-
(FemzipArrayType.STRAIN_XZ, FemzipVariableCategory.SOLID): {ArrayType.element_solid_strain},
243237
# AIRBAG
244238
(FemzipArrayType.AIRBAG_STATE_GEOM, FemzipVariableCategory.CPM_AIRBAG): {
245239
ArrayType.airbag_n_active_particles,

lasso/dyna/lsda_py3.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def writecd(self, dir):
105105
length = self.lengthsize + self.commandsize + len(dir)
106106
s = struct.pack(self.lcunpack, length, Lsda.CD)
107107
self.fp.write(s)
108-
if type(dir) is str:
108+
if isinstance(dir, str):
109109
self.fp.write(bytes(dir, "utf-8"))
110110
else:
111111
self.fp.write(dir)
@@ -118,7 +118,7 @@ def writestentry(self, r):
118118
)
119119
s = struct.pack(self.lcunpack, length, Lsda.VARIABLE)
120120
self.fp.write(s)
121-
if type(r.name) is str:
121+
if isinstance(r.name, str):
122122
self.fp.write(bytes(r.name, "utf-8"))
123123
else:
124124
self.fp.write(r.name)
@@ -353,7 +353,7 @@ def _writesymboltable(lsda, f):
353353
cwd = None
354354

355355
# Write all records
356-
for (s, path) in slist:
356+
for s, path in slist:
357357
if path != cwd:
358358
cdcmd = _get_min_cd(cwd, path)
359359
f.writecd(cdcmd)
@@ -525,7 +525,7 @@ def cd(self, path, create=2): # change CWD
525525
self.cwd = self.root
526526
# path = string.split(path,"/")
527527
# print(type(path))
528-
if type(path) is bytes:
528+
if isinstance(path, bytes):
529529
path = str(path, "utf-8").split("/")
530530
else:
531531
path = path.split("/")
@@ -635,7 +635,7 @@ def nextfile(self): # Open next file in sequence
635635
types = [("b", 1), ("h", 2), ("i", 4), ("q", 8), ("f", 4), ("d", 8)]
636636
x = 17
637637
types_ok = 1
638-
for (a, b) in types:
638+
for a, b in types:
639639
s = struct.pack(a, x)
640640
if len(s) != b:
641641
print("LSDA: initialization error")

lasso/femzip/femzip_api.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -1068,16 +1068,16 @@ def _decompose_read_variables_array(
10681068
(n_timesteps_read, file_metadata.number_of_nodes, 3)
10691069
)
10701070
var_pos += array_size
1071-
result_arrays[
1072-
(variable_index, variable_name, FemzipVariableCategory.NODE)
1073-
] = var_array
1071+
result_arrays[(variable_index, variable_name, FemzipVariableCategory.NODE)] = (
1072+
var_array
1073+
)
10741074
else:
10751075
array_size = file_metadata.number_of_nodes
10761076
var_array = all_vars_array[:, var_pos : var_pos + array_size]
10771077
var_pos += array_size
1078-
result_arrays[
1079-
(variable_index, variable_name, FemzipVariableCategory.NODE)
1080-
] = var_array
1078+
result_arrays[(variable_index, variable_name, FemzipVariableCategory.NODE)] = (
1079+
var_array
1080+
)
10811081

10821082
elif variable_category == FemzipVariableCategory.SHELL:
10831083
array_size = (
@@ -1086,44 +1086,44 @@ def _decompose_read_variables_array(
10861086
)
10871087
var_array = all_vars_array[:, var_pos : var_pos + array_size]
10881088
var_pos += array_size
1089-
result_arrays[
1090-
(variable_index, variable_name, FemzipVariableCategory.SHELL)
1091-
] = var_array
1089+
result_arrays[(variable_index, variable_name, FemzipVariableCategory.SHELL)] = (
1090+
var_array
1091+
)
10921092
elif variable_category == FemzipVariableCategory.SOLID:
10931093
array_size = file_metadata.number_of_solid_elements
10941094
var_array = all_vars_array[:, var_pos : var_pos + array_size]
10951095
var_pos += array_size
1096-
result_arrays[
1097-
(variable_index, variable_name, FemzipVariableCategory.SOLID)
1098-
] = var_array
1096+
result_arrays[(variable_index, variable_name, FemzipVariableCategory.SOLID)] = (
1097+
var_array
1098+
)
10991099
elif variable_category == FemzipVariableCategory.BEAM:
11001100
array_size = file_metadata.number_of_1D_elements
11011101
var_array = all_vars_array[:, var_pos : var_pos + array_size]
11021102
var_pos += array_size
1103-
result_arrays[
1104-
variable_index, variable_name, FemzipVariableCategory.BEAM
1105-
] = var_array
1103+
result_arrays[variable_index, variable_name, FemzipVariableCategory.BEAM] = (
1104+
var_array
1105+
)
11061106
elif variable_category == FemzipVariableCategory.THICK_SHELL:
11071107
array_size = file_metadata.number_of_thick_shell_elements
11081108
var_array = all_vars_array[:, var_pos : var_pos + array_size]
11091109
var_pos += array_size
1110-
result_arrays[
1111-
variable_index, variable_name, FemzipVariableCategory.THICK_SHELL
1112-
] = var_array
1110+
result_arrays[variable_index, variable_name, FemzipVariableCategory.THICK_SHELL] = (
1111+
var_array
1112+
)
11131113
elif variable_category == FemzipVariableCategory.GLOBAL:
11141114
array_size = 6
11151115
var_array = all_vars_array[:, var_pos : var_pos + array_size]
11161116
var_pos += array_size
1117-
result_arrays[
1118-
variable_index, variable_name, FemzipVariableCategory.GLOBAL
1119-
] = var_array
1117+
result_arrays[variable_index, variable_name, FemzipVariableCategory.GLOBAL] = (
1118+
var_array
1119+
)
11201120
elif variable_category == FemzipVariableCategory.PART:
11211121
array_size = n_parts * 7 + n_rigid_walls * n_rigid_wall_vars
11221122
var_array = all_vars_array[:, var_pos : var_pos + array_size]
11231123
var_pos += array_size
1124-
result_arrays[
1125-
variable_index, variable_name, FemzipVariableCategory.PART
1126-
] = var_array
1124+
result_arrays[variable_index, variable_name, FemzipVariableCategory.PART] = (
1125+
var_array
1126+
)
11271127
elif variable_category == FemzipVariableCategory.CPM_FLOAT_VAR:
11281128
array_size = n_airbag_particles
11291129
var_array = all_vars_array[:, var_pos : var_pos + array_size]

lasso/math/sampling.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def unique_subsamples(start: int, end: int, n_samples: int, seed=None) -> np.nda
2525
"""
2626
assert start <= end
2727

28-
if end - start < n_samples:
29-
n_samples = end - start
30-
28+
n_samples = min(n_samples, end - start)
3129
random.seed(seed)
3230
indexes = np.array(random.sample(range(start, end), n_samples), dtype=np.int64)
3331
random.seed()

lasso/utils/decorators.py

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def custom_dir(custom_c, add):
3636

3737

3838
class GetAttr:
39-
4039
"""
4140
Base class for attr accesses in `self._xtra` passed down to `self.default
4241
"""

0 commit comments

Comments
 (0)