Skip to content

Commit 77de512

Browse files
committed
Update CI, and add linting
1 parent f44b9fa commit 77de512

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3431
-1677
lines changed

.github/workflows/check_and_test_package.yml

+35-53
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,78 @@
1-
name: CI
1+
name: OasisMove CI
22

33
on:
44
push:
5-
# The CI is executed on every push on every branch
65
branches:
76
- main
87
pull_request:
9-
# The CI is executed on every pull request to the main branch
108
branches:
119
- main
12-
1310
schedule:
14-
# The CI is executed every day at 8am
15-
- cron: "0 8 * * *"
11+
- cron: '0 8 * * *'
1612

1713
env:
18-
CACHE_NUMBER: 3 # Increase to reset cache
14+
CACHE_NUMBER: 4 # Increase to reset cache
1915

2016
jobs:
21-
check-code:
17+
run-lint-check:
2218
name: Check code
2319
runs-on: ubuntu-latest
2420

2521
steps:
26-
- name: Checkout
27-
uses: actions/checkout@v3
28-
29-
- name: Upgrade pip and setuptools
30-
run: python3 -m pip install pip setuptools --upgrade
22+
- uses: actions/checkout@v3
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.10'
3126

32-
- name: Install OasisMove
33-
run: python3 -m pip install .[test]
27+
- name: Install dependencies and OasisMove
28+
run: |
29+
python -m pip install --upgrade pip setuptools
30+
python -m pip install '.[test]'
3431
35-
- name: Check code with Flake8
36-
run: python3 -m flake8
32+
- name: Run linting and checks
33+
run: |
34+
bash linting.sh
3735
38-
test-code:
39-
needs: check-code
36+
run-tests:
37+
needs: run-lint-check
4038
strategy:
4139
matrix:
4240
include:
4341
- os: ubuntu-latest
4442
label: linux-64
45-
prefix: /usr/share/miniconda3/envs/oasismove
46-
- os: macos-latest
43+
prefix: /usr/share/miniconda3/envs/oasismove-env
44+
- os: macos-13
4745
label: osx-64
48-
prefix: /Users/runner/miniconda3/envs/oasismove
46+
prefix: /Users/runner/miniconda3/envs/oasismove-env
4947

50-
name: Test OasisMove on ${{ matrix.label }}
48+
name: Test OasisMove on ${{ matrix.os}}
5149
runs-on: ${{ matrix.os }}
52-
53-
# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
5450
defaults:
55-
run:
56-
shell: bash -l {0}
51+
run: # https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell
52+
shell: bash -el {0}
5753

5854
steps:
59-
- name: Checkout
60-
uses: actions/checkout@v3
61-
62-
- name: Upgrade pip and setuptools
63-
run: |
64-
python3 -m pip install pip setuptools --upgrade
65-
66-
# See: https://github.com/marketplace/actions/setup-miniconda
67-
- name: Setup Mambaforge
68-
uses: conda-incubator/setup-miniconda@v2
55+
- uses: actions/checkout@v4
56+
- uses: mamba-org/setup-micromamba@v1
6957
with:
70-
miniforge-variant: Mambaforge
71-
miniforge-version: latest
72-
channels: conda-forge
73-
activate-environment: oasismove
74-
use-mamba: true
58+
environment-file: environment.yml
59+
init-shell: bash
60+
cache-environment: true
7561

76-
- name: Set cache date
77-
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
78-
79-
- uses: actions/cache@v2
62+
- uses: actions/cache@v3
8063
with:
8164
path: ${{ matrix.prefix }}
82-
key: ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
83-
id: cache
65+
key: ${{ matrix.label }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.yml') }}
66+
restore-keys: ${{ matrix.label }}-${{ env.CACHE_NUMBER }}-
8467

85-
- name: Update environment
86-
run: mamba env update -n oasismove -f environment.yml
87-
if: steps.cache.outputs.cache-hit != 'true'
8868

8969
- name: Install OasisMove
90-
run: python3 -m pip install --editable .[test]
70+
run: |
71+
python -m pip install '.[test]'
9172
9273
- name: Run tests
93-
run: python3 -m pytest tests
74+
run: |
75+
python -m pytest tests
9476
9577
- name: Upload coverage report to codecov
9678
if: matrix.os == 'ubuntu-latest'

linting.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /usr/bin/env bash
2+
3+
isort src tests
4+
5+
black src tests
6+
7+
flake8 src tests

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ test = [
1717
"flake8",
1818
"pytest",
1919
"pytest-cov",
20+
"isort",
21+
"black"
2022
]
2123
docs = [
2224
"jupyter-book",

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
jupyter-book
22
matplotlib
33
numpy
4-
ghp-import
4+
ghp-import

src/oasismove/NSCoupled.py

+48-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
__author__ = 'Mikael Mortensen <[email protected]>'
2-
__date__ = '2014-04-04'
3-
__copyright__ = 'Copyright (C) 2014 ' + __author__
4-
__license__ = 'GNU Lesser GPL version 3 or any later version'
1+
__author__ = "Mikael Mortensen <[email protected]>"
2+
__date__ = "2014-04-04"
3+
__copyright__ = "Copyright (C) 2014 " + __author__
4+
__license__ = "GNU Lesser GPL version 3 or any later version"
55

66
import importlib
77

@@ -27,16 +27,18 @@
2727
commandline_kwargs = parse_command_line()
2828

2929
# Find the problem module
30-
default_problem = 'DrivenCavity'
31-
problemname = commandline_kwargs.get('problem', default_problem)
32-
problemspec = importlib.util.find_spec('.'.join(('oasismove.problems.NSCoupled', problemname)))
30+
default_problem = "DrivenCavity"
31+
problemname = commandline_kwargs.get("problem", default_problem)
32+
problemspec = importlib.util.find_spec(
33+
".".join(("oasismove.problems.NSCoupled", problemname))
34+
)
3335
if problemspec is None:
3436
problemspec = importlib.util.find_spec(problemname)
3537
if problemspec is None:
36-
raise RuntimeError(problemname + ' not found')
38+
raise RuntimeError(problemname + " not found")
3739

3840
# Import the problem module
39-
print('Importing problem module ' + problemname + ':\n' + problemspec.origin)
41+
print("Importing problem module " + problemname + ":\n" + problemspec.origin)
4042
problemmod = importlib.util.module_from_spec(problemspec)
4143
problemspec.loader.exec_module(problemmod)
4244

@@ -49,33 +51,34 @@
4951
vars().update(post_import_problem(**vars()))
5052

5153
# Import chosen functionality from solvers
52-
solver = importlib.import_module('.'.join(('oasismove.solvers.NSCoupled', solver)))
54+
solver = importlib.import_module(".".join(("oasismove.solvers.NSCoupled", solver)))
5355
vars().update({name: solver.__dict__[name] for name in solver.__all__})
5456

5557
# Create lists of components solved for
56-
u_components = ['u']
57-
sys_comp = ['up'] + scalar_components
58+
u_components = ["u"]
59+
sys_comp = ["up"] + scalar_components
5860

5961
# Get the chosen mixed elment
60-
element = commandline_kwargs.get('element', 'TaylorHood')
62+
element = commandline_kwargs.get("element", "TaylorHood")
6163
vars().update(elements[element])
6264

6365
# TaylorHood may overload degree of elements
64-
if element == 'TaylorHood':
65-
degree['u'] = commandline_kwargs.get('velocity_degree', degree['u'])
66-
degree['p'] = commandline_kwargs.get('pressure_degree', degree['p'])
66+
if element == "TaylorHood":
67+
degree["u"] = commandline_kwargs.get("velocity_degree", degree["u"])
68+
degree["p"] = commandline_kwargs.get("pressure_degree", degree["p"])
6769
# Should assert that degree['p'] = degree['u']-1 ??
6870

6971
# Declare Elements
70-
V = VectorElement(family['u'], mesh.ufl_cell(), degree['u'])
71-
Q = FiniteElement(family['p'], mesh.ufl_cell(), degree['p'])
72+
V = VectorElement(family["u"], mesh.ufl_cell(), degree["u"])
73+
Q = FiniteElement(family["p"], mesh.ufl_cell(), degree["p"])
7274

7375
# Create Mixed space
7476
# MINI element has bubble, add to V
7577
if bubble:
7678
B = VectorElement("Bubble", mesh.ufl_cell(), mesh.geometry().dim() + 1)
77-
VQ = FunctionSpace(mesh, MixedElement(V + B, Q),
78-
constrained_domain=constrained_domain)
79+
VQ = FunctionSpace(
80+
mesh, MixedElement(V + B, Q), constrained_domain=constrained_domain
81+
)
7982

8083
else:
8184
VQ = FunctionSpace(mesh, V * Q, constrained_domain=constrained_domain)
@@ -86,7 +89,7 @@
8689
v, q = TestFunctions(VQ)
8790

8891
# For scalars use CG space
89-
CG = FunctionSpace(mesh, 'CG', 1, constrained_domain=constrained_domain)
92+
CG = FunctionSpace(mesh, "CG", 1, constrained_domain=constrained_domain)
9093
c = TrialFunction(CG)
9194
ct = TestFunction(CG)
9295

@@ -95,17 +98,19 @@
9598

9699
# Create dictionaries for the solutions at two timesteps
97100
q_ = dict((ui, Function(VV[ui], name=ui)) for ui in sys_comp)
98-
q_1 = dict((ui, Function(VV[ui], name=ui + '_1')) for ui in sys_comp)
101+
q_1 = dict((ui, Function(VV[ui], name=ui + "_1")) for ui in sys_comp)
99102

100103
# Short forms
101-
up_ = q_['up'] # Solution at next iteration
102-
up_1 = q_1['up'] # Solution at previous iteration
104+
up_ = q_["up"] # Solution at next iteration
105+
up_1 = q_1["up"] # Solution at previous iteration
103106
u_, p_ = split(up_)
104107
u_1, p_1 = split(up_1)
105108

106109
# Create short forms for accessing the solution vectors
107110
x_ = dict((ui, q_[ui].vector()) for ui in sys_comp) # Solution vectors
108-
x_1 = dict((ui, q_1[ui].vector()) for ui in sys_comp) # Solution vectors previous iteration
111+
x_1 = dict(
112+
(ui, q_1[ui].vector()) for ui in sys_comp
113+
) # Solution vectors previous iteration
109114

110115
# Create vectors to hold rhs of equations
111116
b = dict((ui, Vector(x_[ui])) for ui in sys_comp)
@@ -154,7 +159,7 @@ def iterate(iters=max_iter):
154159
x_1[ui].zero()
155160
x_1[ui].axpy(1.0, x_[ui])
156161

157-
error = b['up'].norm('l2')
162+
error = b["up"].norm("l2")
158163
print_velocity_pressure_info(**locals())
159164

160165
iter += 1
@@ -171,25 +176,25 @@ def iterate_scalar(iters=max_iter, errors=max_error):
171176
scalar_assemble(**globals())
172177
scalar_hook(**globals())
173178
scalar_solve(**globals())
174-
err[ci] = b[ci].norm('l2')
179+
err[ci] = b[ci].norm("l2")
175180
if MPI.rank(MPI.comm_world) == 0:
176-
print('Iter {}, Error {} = {}'.format(citer, ci, err[ci]))
181+
print("Iter {}, Error {} = {}".format(citer, ci, err[ci]))
177182
citer += 1
178183

179184

180-
timer = OasisTimer('Start Newton iterations flow', True)
185+
timer = OasisTimer("Start Newton iterations flow", True)
181186
# Assemble rhs once, before entering iterations (velocity components)
182-
b['up'] = assemble(Fs['up'], tensor=b['up'])
183-
for bc in bcs['up']:
184-
bc.apply(b['up'], x_['up'])
187+
b["up"] = assemble(Fs["up"], tensor=b["up"])
188+
for bc in bcs["up"]:
189+
bc.apply(b["up"], x_["up"])
185190

186191
iterate(max_iter)
187192
timer.stop()
188193

189194
# Assuming there is no feedback to the flow solver from the scalar field,
190195
# we solve the scalar only after converging the flow
191196
if len(scalar_components) > 0:
192-
scalar_timer = OasisTimer('Start Newton iterations scalars', True)
197+
scalar_timer = OasisTimer("Start Newton iterations scalars", True)
193198
# Assemble rhs once, before entering iterations (velocity components)
194199
for scalar in scalar_components:
195200
b[scalar] = assemble(Fs[scalar], tensor=b[scalar])
@@ -200,13 +205,17 @@ def iterate_scalar(iters=max_iter, errors=max_error):
200205
scalar_timer.stop()
201206

202207
list_timings(TimingClear.keep, [TimingType.wall])
203-
info_red('Total computing time = {0:f}'.format(timer.elapsed()[0]))
204-
oasis_memory('Final memory use ')
208+
info_red("Total computing time = {0:f}".format(timer.elapsed()[0]))
209+
oasis_memory("Final memory use ")
205210
total_initial_dolfin_memory = MPI.sum(MPI.comm_world, initial_memory_use)
206-
info_red('Memory use for importing dolfin = {} MB (RSS)'.format(
207-
total_initial_dolfin_memory))
208-
info_red('Total memory use of solver = ' +
209-
str(oasis_memory.memory - total_initial_dolfin_memory) + ' MB (RSS)')
211+
info_red(
212+
"Memory use for importing dolfin = {} MB (RSS)".format(total_initial_dolfin_memory)
213+
)
214+
info_red(
215+
"Total memory use of solver = "
216+
+ str(oasis_memory.memory - total_initial_dolfin_memory)
217+
+ " MB (RSS)"
218+
)
210219

211220
# Final hook
212221
theend_hook(**vars())

0 commit comments

Comments
 (0)