diff --git a/.github/workflows/pep8.yml b/.github/workflows/pep8.yml new file mode 100644 index 00000000..9b9e9fa2 --- /dev/null +++ b/.github/workflows/pep8.yml @@ -0,0 +1,45 @@ +name: Pep8 + +on: + push: + branches: + - main + +jobs: + autopep8: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: autopep8 + uses: peter-evans/autopep8@v2 + with: + args: --recursive --in-place --aggressive --aggressive . + + - name: Check for changes + id: check-changes + run: git diff --exit-code + continue-on-error: true + + - name: Commit and push changes + # a failue of this step means changes were detected + if: steps.check-changes.outcome != 'success' + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + git commit -am "Auto-format code using Clang-Format" || echo "No changes to commit" + + - name: Push changes to main-autopep8 branch + if: steps.check-changes.outcome != 'success' + run: git push origin HEAD:main-autopep8 + + - name: Create Pull Request + if: steps.check-changes.outcome != 'success' + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "Auto-format code using autopep8" + title: "Auto-format code by autopep8" + body: "This is an auto-generated PR with fixes by autopep8." + branch: main-autopep8 \ No newline at end of file diff --git a/docs/source/conf.py b/docs/source/conf.py index 29217117..d64a11bc 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -22,7 +22,8 @@ author = 'NCAR/UCAR' suffix = '' -# the suffix is required. This is controlled by the dockerfile that builds the docs +# the suffix is required. This is controlled by the dockerfile that builds +# the docs release = f'0.0.0' # -- General configuration --------------------------------------------------- @@ -31,9 +32,9 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx_copybutton', - 'sphinx_design', - 'sphinxcontrib.bibtex', + 'sphinx_copybutton', + 'sphinx_design', + 'sphinxcontrib.bibtex', ] bibtex_bibfiles = ['references.bib'] @@ -59,8 +60,8 @@ "external_links": [], "github_url": "https://github.com/NCAR/musica", "navbar_end": ["version-switcher", "navbar-icon-links"], - "pygment_light_style": "tango", - "pygment_dark_style": "monokai" + "pygment_light_style": "tango", + "pygment_dark_style": "monokai" } html_css_files = [ diff --git a/python/test/analytical.py b/python/test/analytical.py index 685e2519..4dfae1a5 100644 --- a/python/test/analytical.py +++ b/python/test/analytical.py @@ -2,13 +2,14 @@ import numpy as np import musica + class TestAnalyticalSimulation(unittest.TestCase): def test_simulation(self): time_step = 200.0 temperature = 272.5 pressure = 101253.3 - solver = musica.create_micm("configs/analytical") + solver = musica.create_micm("configs/analytical") rates = musica.user_defined_reaction_rates(solver) ordering = musica.species_ordering(solver) @@ -18,14 +19,15 @@ def test_simulation(self): self.assertEqual(ordering['B'], 1) self.assertEqual(ordering['C'], 2) - # Initalizes concentrations + # Initalizes concentrations initial_concentrations = [1, 0, 0] model_concentrations = [initial_concentrations[:]] analytical_concentrations = [initial_concentrations[:]] k1 = 4.0e-3 * np.exp(50 / temperature) - k2 = 1.2e-4 * np.exp(75 / temperature) * (temperature / 50)**7* (1.0 + 0.5 * pressure) + k2 = 1.2e-4 * np.exp(75 / temperature) * \ + (temperature / 50)**7 * (1.0 + 0.5 * pressure) time_step = 1 sim_length = 100 @@ -38,23 +40,41 @@ def test_simulation(self): concentrations = initial_concentrations - # Gets analytical concentrations + # Gets analytical concentrations while curr_time <= sim_length: - musica.micm_solve(solver, time_step, temperature, pressure, concentrations, None) + musica.micm_solve( + solver, + time_step, + temperature, + pressure, + concentrations, + None) model_concentrations.append(concentrations[:]) initial_A = analytical_concentrations[0][idx_A] - A_conc = initial_A * np.exp(-(k1)* curr_time) - B_conc = initial_A * (k1 / (k2 - k1)) * (np.exp(-k1 * curr_time) - np.exp(-k2 * curr_time)) - C_conc = initial_A * (1.0 + (k1 * np.exp(-k2 * curr_time) - k2 * np.exp(-k1 * curr_time)) / (k2 - k1)) + A_conc = initial_A * np.exp(-(k1) * curr_time) + B_conc = initial_A * \ + (k1 / (k2 - k1)) * (np.exp(-k1 * curr_time) - np.exp(-k2 * curr_time)) + C_conc = initial_A * \ + (1.0 + (k1 * np.exp(-k2 * curr_time) - k2 * np.exp(-k1 * curr_time)) / (k2 - k1)) analytical_concentrations.append([A_conc, B_conc, C_conc]) curr_time += time_step for i in range(len(model_concentrations)): - self.assertAlmostEqual(model_concentrations[i][idx_A], analytical_concentrations[i][idx_A], places=8) - self.assertAlmostEqual(model_concentrations[i][idx_B], analytical_concentrations[i][idx_B], places=8) - self.assertAlmostEqual(model_concentrations[i][idx_C], analytical_concentrations[i][idx_C], places=8) + self.assertAlmostEqual( + model_concentrations[i][idx_A], + analytical_concentrations[i][idx_A], + places=8) + self.assertAlmostEqual( + model_concentrations[i][idx_B], + analytical_concentrations[i][idx_B], + places=8) + self.assertAlmostEqual( + model_concentrations[i][idx_C], + analytical_concentrations[i][idx_C], + places=8) + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/python/test/chapman.py b/python/test/chapman.py index 87b46ec8..4cfebc91 100644 --- a/python/test/chapman.py +++ b/python/test/chapman.py @@ -1,6 +1,7 @@ import unittest import musica + class TestChapman(unittest.TestCase): def test_micm_solve(self): time_step = 200.0 @@ -8,25 +9,35 @@ def test_micm_solve(self): pressure = 101253.3 concentrations = [0.75, 0.4, 0.8, 0.01, 0.02] - solver = musica.create_micm("configs/chapman") + solver = musica.create_micm("configs/chapman") rate_constant_ordering = musica.user_defined_reaction_rates(solver) ordering = musica.species_ordering(solver) rate_constants = { - "PHOTO.R1" : 2.42e-17, - "PHOTO.R3" : 1.15e-5, - "PHOTO.R5" : 6.61e-9 + "PHOTO.R1": 2.42e-17, + "PHOTO.R3": 1.15e-5, + "PHOTO.R5": 6.61e-9 } ordered_rate_constants = len(rate_constants.keys()) * [0.0] for key, value in rate_constants.items(): ordered_rate_constants[rate_constant_ordering[key]] = value - - musica.micm_solve(solver, time_step, temperature, pressure, concentrations, ordered_rate_constants) - self.assertEqual(ordering, {'M': 0, 'O': 2, 'O1D': 1, 'O2': 3, 'O3': 4}) - self.assertEqual(rate_constant_ordering, {'PHOTO.R1': 0, 'PHOTO.R3': 1, 'PHOTO.R5': 2}) + musica.micm_solve( + solver, + time_step, + temperature, + pressure, + concentrations, + ordered_rate_constants) + + self.assertEqual( + ordering, { + 'M': 0, 'O': 2, 'O1D': 1, 'O2': 3, 'O3': 4}) + self.assertEqual( + rate_constant_ordering, { + 'PHOTO.R1': 0, 'PHOTO.R3': 1, 'PHOTO.R5': 2}) self.assertEqual(concentrations[0], 0.75) self.assertNotEqual(concentrations[1], 0.4) @@ -34,5 +45,6 @@ def test_micm_solve(self): self.assertNotEqual(concentrations[3], 0.01) self.assertNotEqual(concentrations[4], 0.02) + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()