kumiori / irrevolutions

Computing Irreversible Evolutions
GNU General Public License v3.0
12 stars 5 forks source link

Import order of MPI, PETSc, DOLFINx etc #63

Closed jorgensd closed 1 month ago

jorgensd commented 2 months ago

Something that came to our attention last year is that it is quite important what order you import MPI, PETSc and DOLFINx in. https://github.com/FEniCS/dolfinx/pull/2826

You can use a setup in your pyproject.toml along the lines of: https://github.com/FEniCS/dolfinx/blob/main/python/pyproject.toml#L104-L117 and use ruff to auto-sort all imports.

jhale commented 2 months ago

I would recommend just running ruff format . and ruff check . on the entire codebase.

kumiori commented 2 months ago

Thank you for the suggestion, with the ruff tool isort setup in the indicated pyprojet file, we used ruff to sort imports, format, and fix other recurring issues.

jorgensd commented 2 months ago

Running ruff on the code currently I get:

src/irrevolutions/algorithms/am.py:22:1: E402 Module level import not at top of file
src/irrevolutions/algorithms/ls.py:150:9: F841 Local variable `upperbound` is assigned to but never used
src/irrevolutions/algorithms/ls.py:151:9: F841 Local variable `lowerbound` is assigned to but never used
src/irrevolutions/algorithms/so.py:327:13: F841 Local variable `v` is assigned to but never used
src/irrevolutions/algorithms/so.py:384:68: F841 Local variable `timer` is assigned to but never used
src/irrevolutions/algorithms/so.py:839:9: F841 Local variable `n2` is assigned to but never used
src/irrevolutions/meshes/__init__.py:22:34: E711 Comparison to `None` should be `cond is None`
src/irrevolutions/meshes/boolean.py:30:9: F841 Local variable `boolean` is assigned to but never used
src/irrevolutions/meshes/extended_pacman.py:68:9: F841 Local variable `p3` is assigned to but never used
src/irrevolutions/meshes/extended_pacman.py:84:9: F841 Local variable `p30` is assigned to but never used
src/irrevolutions/meshes/pacman.py:36:9: F841 Local variable `elltomesh` is assigned to but never used
src/irrevolutions/meshes/pacman.py:48:9: F841 Local variable `entities` is assigned to but never used
src/irrevolutions/meshes/pacman.py:72:9: F841 Local variable `p3` is assigned to but never used
src/irrevolutions/meshes/primitives.py:146:9: F841 Local variable `pRa` is assigned to but never used
src/irrevolutions/meshes/primitives.py:147:9: F841 Local variable `pRb` is assigned to but never used
src/irrevolutions/meshes/primitives.py:151:9: F841 Local variable `prM` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:49:9: F841 Local variable `p5` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:50:9: F841 Local variable `p500` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:51:9: F841 Local variable `p501` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:52:9: F841 Local variable `p502` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:53:9: F841 Local variable `p503` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:54:9: F841 Local variable `p6` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:55:9: F841 Local variable `p600` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:56:9: F841 Local variable `p601` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:57:9: F841 Local variable `p602` is assigned to but never used
src/irrevolutions/meshes/tdcb_2D.py:58:9: F841 Local variable `p603` is assigned to but never used
src/irrevolutions/models/__init__.py:254:1: E402 Module level import not at top of file
src/irrevolutions/practice/default.py:91:5: F841 Local variable `Lx` is assigned to but never used
src/irrevolutions/practice/default.py:92:5: F841 Local variable `Ly` is assigned to but never used
src/irrevolutions/practice/default.py:93:5: F841 Local variable `tdim` is assigned to but never used
src/irrevolutions/practice/default.py:96:5: F841 Local variable `ell_` is assigned to but never used
src/irrevolutions/practice/default.py:193:5: F841 Local variable `dofs_alpha_left` is assigned to but never used
src/irrevolutions/practice/default.py:194:5: F841 Local variable `dofs_alpha_right` is assigned to but never used
src/irrevolutions/practice/default.py:202:5: F841 Local variable `zero_alpha` is assigned to but never used
src/irrevolutions/practice/default.py:269:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/default.py:470:5: F841 Local variable `u` is assigned to but never used
src/irrevolutions/practice/default.py:475:9: E731 Do not assign a `lambda` expression, use a `def`
src/irrevolutions/practice/discrete_atk.py:213:5: F841 Local variable `model_rank` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:235:5: F841 Local variable `Ly` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:236:5: F841 Local variable `tdim` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:239:5: F841 Local variable `ell_` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:243:5: F841 Local variable `geom_type` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:318:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:322:5: F841 Local variable `dofs_alpha_left` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:323:5: F841 Local variable `dofs_alpha_right` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:365:9: F841 Local variable `k_res` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:426:5: F841 Local variable `external_work` is assigned to but never used
src/irrevolutions/practice/discrete_atk.py:543:9: F821 Undefined name `plot_energies`
src/irrevolutions/practice/discrete_atk_homogeneous.py:214:5: F841 Local variable `model_rank` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:236:5: F841 Local variable `Ly` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:237:5: F841 Local variable `tdim` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:240:5: F841 Local variable `ell_` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:244:5: F841 Local variable `geom_type` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:314:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:318:5: F841 Local variable `dofs_alpha_left` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:319:5: F841 Local variable `dofs_alpha_right` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:361:9: F841 Local variable `k_res` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:422:5: F841 Local variable `external_work` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:427:5: F841 Local variable `solver` is assigned to but never used
src/irrevolutions/practice/discrete_atk_homogeneous.py:570:9: F821 Undefined name `plot_energies`
src/irrevolutions/practice/multiaxial-disc.py:84:5: F841 Local variable `model_rank` is assigned to but never used
src/irrevolutions/practice/multiaxial-disc.py:87:9: F841 Local variable `parameters` is assigned to but never used
src/irrevolutions/practice/pacman-cone.py:98:5: F841 Local variable `Lx` is assigned to but never used
src/irrevolutions/practice/pacman-cone.py:99:5: F841 Local variable `Ly` is assigned to but never used
src/irrevolutions/practice/pacman-cone.py:195:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/pacman-cone.py:242:5: F841 Local variable `bcs_z` is assigned to but never used
src/irrevolutions/practice/pacman-cone.py:259:5: F841 Local variable `solver` is assigned to but never used
src/irrevolutions/practice/pacman-cone.py:331:9: F841 Local variable `is_stable` is assigned to but never used
src/irrevolutions/practice/pacman_hybrid.py:107:5: F841 Local variable `Lx` is assigned to but never used
src/irrevolutions/practice/pacman_hybrid.py:108:5: F841 Local variable `Ly` is assigned to but never used
src/irrevolutions/practice/pacman_hybrid.py:177:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/pacman_hybrid.py:224:5: F841 Local variable `bcs_z` is assigned to but never used
src/irrevolutions/practice/pacman_hybrid.py:253:5: F841 Local variable `F` is assigned to but never used
src/irrevolutions/practice/pacman_hybrid.py:254:5: F841 Local variable `z` is assigned to but never used
src/irrevolutions/practice/pacman_hybrid.py:274:5: F841 Local variable `snes` is assigned to but never used
src/irrevolutions/practice/thinfilm-bar.py:161:5: F841 Local variable `perturbation` is assigned to but never used
src/irrevolutions/practice/thinfilm-bar.py:163:5: F841 Local variable `z` is assigned to but never used
src/irrevolutions/practice/thinfilm-bar.py:170:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/thinfilm-bar.py:178:5: F841 Local variable `zero_alpha` is assigned to but never used
src/irrevolutions/practice/thinfilm-bar.py:294:9: F841 Local variable `is_stable` is assigned to but never used
src/irrevolutions/practice/thinfilm-bar.py:295:9: F841 Local variable `is_elastic` is assigned to but never used
src/irrevolutions/practice/thinfilm-bar.py:345:13: F841 Local variable `ax` is assigned to but never used
src/irrevolutions/practice/thinfilm-bar.py:403:61: F841 Local variable `timer` is assigned to but never used
src/irrevolutions/practice/traction-AT1_cone.py:105:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_cone.py:366:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_cone.py:374:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_cone.py:376:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_cone.py:377:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_cone.py:378:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_first_order.py:108:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_first_order.py:361:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_first_order.py:369:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_first_order.py:371:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_first_order.py:372:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT1_first_order.py:373:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT2_cone.py:88:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT2_cone.py:312:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT2_cone.py:319:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT2_cone.py:321:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT2_cone.py:322:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-AT2_cone.py:323:1: E402 Module level import not at top of file
src/irrevolutions/practice/traction-ATJJ.py:145:17: F821 Undefined name `hashlib`
src/irrevolutions/practice/traction-ATJJ.py:165:17: F821 Undefined name `hashlib`
src/irrevolutions/practice/traction-ATJJ.py:208:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/traction-ATJJ.py:210:5: F841 Local variable `dofs_alpha_left` is assigned to but never used
src/irrevolutions/practice/traction-ATJJ.py:211:5: F841 Local variable `dofs_alpha_right` is assigned to but never used
src/irrevolutions/practice/traction-ATJJ.py:463:9: F821 Undefined name `plot_energies`
src/irrevolutions/practice/traction-ATJJ.py:510:5: F841 Local variable `ax` is assigned to but never used
src/irrevolutions/practice/traction-ATJJ.py:535:19: E711 Comparison to `None` should be `cond is None`
src/irrevolutions/practice/traction-ATJJ.py:607:19: E711 Comparison to `None` should be `cond is None`
src/irrevolutions/practice/traction-ATJJ.py:684:19: E711 Comparison to `None` should be `cond is None`
src/irrevolutions/practice/traction-bar-clean.py:143:5: F841 Local variable `ell_` is assigned to but never used
src/irrevolutions/practice/traction-bar-clean.py:193:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/traction-bar-clean.py:210:5: F841 Local variable `perturbation` is assigned to but never used
src/irrevolutions/practice/traction-bar-clean.py:400:5: F841 Local variable `df` is assigned to but never used
src/irrevolutions/practice/traction-bar-clean.py:402:61: F841 Local variable `timer` is assigned to but never used
src/irrevolutions/practice/traction-bar-clean.py:469:9: F841 Local variable `ax` is assigned to but never used
src/irrevolutions/practice/traction-cone.py:75:17: F821 Undefined name `hashlib`
src/irrevolutions/practice/traction-cone.py:95:17: F821 Undefined name `hashlib`
src/irrevolutions/practice/traction-cone.py:140:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/traction-cone.py:142:5: F841 Local variable `dofs_alpha_left` is assigned to but never used
src/irrevolutions/practice/traction-cone.py:143:5: F841 Local variable `dofs_alpha_right` is assigned to but never used
src/irrevolutions/practice/traction-cone.py:396:22: F821 Undefined name `parameters_vs_ell`
src/irrevolutions/practice/traction-cone.py:416:22: F821 Undefined name `parameters_vs_SPA_scaling`
src/irrevolutions/practice/traction-parametric.py:72:9: F841 Local variable `t` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:74:9: F841 Local variable `u` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:75:9: F841 Local variable `alpha` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:200:5: F841 Local variable `ds` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:202:5: F841 Local variable `dofs_alpha_left` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:203:5: F841 Local variable `dofs_alpha_right` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:246:5: F841 Local variable `solver` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:392:61: F841 Local variable `timer` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:498:65: F841 Local variable `timer` is assigned to but never used
src/irrevolutions/practice/traction-parametric.py:549:65: F841 Local variable `timer` is assigned to but never used
src/irrevolutions/practice/unstabinst.py:107:5: F841 Local variable `c0` is assigned to but never used
src/irrevolutions/solvers/__init__.py:11:1: E402 Module level import not at top of file
src/irrevolutions/solvers/__init__.py:14:1: E402 Module level import not at top of file
src/irrevolutions/utils/__init__.py:87:5: F841 Local variable `size` is assigned to but never used
src/irrevolutions/utils/__init__.py:196:1: E402 Module level import not at top of file
src/irrevolutions/utils/__init__.py:197:1: E402 Module level import not at top of file
src/irrevolutions/utils/__init__.py:198:1: E402 Module level import not at top of file
src/irrevolutions/utils/__init__.py:288:1: E402 Module level import not at top of file
src/irrevolutions/utils/__init__.py:435:27: F821 Undefined name `PEtest_binarydataioTSc`
src/irrevolutions/utils/__init__.py:456:38: F821 Undefined name `translatePETScERROR`
src/irrevolutions/utils/eigenspace.py:106:5: F841 Local variable `v` is assigned to but never used
src/irrevolutions/utils/viz.py:10:1: E402 Module level import not at top of file
src/irrevolutions/utils/viz.py:14:1: E402 Module level import not at top of file
src/irrevolutions/utils/viz.py:18:1: E402 Module level import not at top of file
src/irrevolutions/utils/viz.py:19:1: E402 Module level import not at top of file
src/irrevolutions/utils/viz.py:23:1: E402 Module level import not at top of file
src/irrevolutions/utils/viz.py:24:1: E402 Module level import not at top of file
src/irrevolutions/utils/viz.py:25:1: E402 Module level import not at top of file
src/irrevolutions/utils/viz.py:229:9: F841 Local variable `ax` is assigned to but never used
src/irrevolutions/utils/viz.py:239:1: E402 Module level import not at top of file

Would be great to clear these, even if I wouldn't say it is a must

kumiori commented 1 month ago

Thanks for pointing out. All warnings have been cleared on main.