Skip to content

Commit

Permalink
Clean up benchmarks and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wigging committed Jan 2, 2024
1 parent 0dc9bb5 commit 2844137
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 32 deletions.
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@

The following is a set of guidelines for contributing to the Chemics Python package. Submitted code that does not conform to these guidelines will not be merged into the package. Feel free to propose changes to this document in a Pull Request or Issue.

## Environment
## Development environment

Use the `environment.yml` file to create a conda environment for developing the Chemics package. See the comments in the file for more details.

## Code style
## Code style, linting, and formatting

All code in the Chemics package should adhere to the style enforced by the [Flake8](https://pypi.org/project/flake8/) tool. This will ensure a consistent code format throughout the package and prevent syntax errors during development. For the Flake8 style settings, ignore the E501, W503, W605 errors and warnings.
All Python code in the Chemics package should adhere to the [PEP 8](https://peps.python.org/pep-0008/) style guide. All linting and formatting should be implemented with [ruff](https://github.com/astral-sh/ruff). Configuration for ruff is defined in the pyproject.toml file.

## Docstrings

All functions, classes, and other Python components should contain docstrings with syntax and best practices outlined by the [NumPy docstring guide](https://numpydoc.readthedocs.io/en/latest/format.html). Within the docstring, use the references section to list references used to develop that function or method. A simple example of how to use a function or class should be included in its docstring.

## Examples

Along with an example in the docstring, please provide a complete example in Sphinx documentation. Simple examples should also be provided in the docstrings.
Along with an example in the docstring, please provide a complete example in the Sphinx documentation. Simple examples should also be provided in the docstrings.

## Tests

New code for the Chemics package must include associated tests in the `tests/` folder. The [pytest](https://docs.pytest.org/en/latest/) framework is used to execute the test files.
New code for the Chemics package must include associated tests in the `tests/` folder. The [pytest](https://github.com/pytest-dev/pytest) framework is used to execute the test files.

## Changelog

Don't forget to edit the changelog based on your contributions. Follow the style on the [Keep a Changelog](https://keepachangelog.com) website.

## Sphinx documentation

New source code should be included in the [Sphinx documentation](http://www.sphinx-doc.org/en/stable/) located in the `docs/` folder.
New source code along with examples should be documented in the [Sphinx documentation](http://www.sphinx-doc.org/en/stable/) located in the `docs/` folder.

## Creating a pull request

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Chemics
Copyright (c) 2024 Chemics

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,39 @@ $ pip install chemics

## Usage

The example below imports the Chemics package and creates a `Gas` class to calculate the density of nitrogen gas at a pressure of 101,325 Pa and 773 K.
The example below imports the Chemics package and uses the `Gas` class to calculate the density and viscosity of nitrogen gas at a temperature of 773 K and pressure of 101,325 Pa.

```python
import chemics as cm

gas = cm.Gas('N2')
rho = gas.density(101325, 773)
gas = cm.Gas("N2", 773)
rho = gas.density()
mu = gas.viscosity()

print(rho)
# This prints a value of 0.4416
print("Nitrogen gas properties at 773 K and 101,325 Pa")
print(f"density {rho:.4f} kg/m³")
print(f"viscosity {mu:.2f} μP")
```

This prints the following:

```
Nitrogen gas properties at 773 K and 101,325 Pa
density 0.4416 kg/m³
viscosity 363.82 μP
```

This example uses the `ChemicalEquation` class to get properties of the reactants and products from a given chemical equation.

```python
import chemics as cm

ce = cm.ChemicalEquation('2 HCl + 2 Na -> 2 NaCl + H2')
ce = cm.ChemicalEquation("2 HCl + 2 Na -> 2 NaCl + H2")
ce.is_balanced()
# Returns True for balanced equation
# This returns True for balanced equation

ce.rct_properties
# Returns a dataframe of the reactant properties
# This returns a dataframe of the reactant properties
# HCl Na
# moles 2 2
# species HCl Na
Expand Down
25 changes: 17 additions & 8 deletions benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
"""
Benchmarks.
"""

import time
import chemics as cm


def run_benchmarks():
"""
Run benchmarks for the Gas methods. Elapsed time for subsequent method
calls should be near zero compared to the initial method execution.
"""
Run benchmarks for Gas methods.
gas = cm.Gas('CH4', 890.5, 120325)
Run benchmarks for Gas heat capacity, thermal conductivity, and viscosity
methods. Elapsed time for subsequent method calls should be near zero
compared to the initial method execution.
"""
gas = cm.Gas("CH4", 890.5, 120325)

for i in range(5):
tic = time.perf_counter()
cp = gas.heat_capacity()
toc = time.perf_counter()
print(f'Run {i + 1}, Elapsed time {toc - tic:.4f} s, cp {cp:.4f}')
print(f"Run {i + 1}, Elapsed time {toc - tic:.4f} s, cp {cp:.4f}")
print()

for i in range(5):
tic = time.perf_counter()
k = gas.thermal_conductivity()
toc = time.perf_counter()
print(f'Run {i + 1}, Elapsed time {toc - tic:.4f} s, k {k:.4f}')
print(f"Run {i + 1}, Elapsed time {toc - tic:.4f} s, k {k:.4f}")
print()

for i in range(5):
tic = time.perf_counter()
mu = gas.viscosity()
toc = time.perf_counter()
print(f'Run {i + 1}, Elapsed time {toc - tic:.4f} s, mu {mu:.4f}')
print(f"Run {i + 1}, Elapsed time {toc - tic:.4f} s, mu {mu:.4f}")


def main():
"""
Run the benchmarks.
"""
run_benchmarks()


if __name__ == '__main__':
if __name__ == "__main__":
main()
2 changes: 0 additions & 2 deletions docs/examples/gas_properties.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ This prints the output shown below.
heat capacity 31.24 J/(mol⋅K)
thermal conductivity 0.054 W/(m⋅K)
viscosity 363.82 microPoise (μP)

Done.
24 changes: 17 additions & 7 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ Install Chemics using the pip package manager:
Usage
=====

The example below imports the chemics package and creates a ``Gas`` class to calculate the density of nitrogen gas at a pressure of 101,325 Pa and 773 K.
The example below imports the Chemics package and uses the ``Gas`` class to calculate the density and viscosity of nitrogen gas at a temperature of 773 K and pressure of 101,325 Pa.

.. code-block:: python
.. testcode::

import chemics as cm

gas = cm.Gas('N2')
rho = gas.density(101325, 773)
print(rho)
# This prints a value of 0.4416
gas = cm.Gas("N2", 773)
rho = gas.density()
mu = gas.viscosity()

print("Nitrogen gas properties at 773 K and 101,325 Pa")
print(f"density {rho:.4f} kg/m³")
print(f"viscosity {mu:.2f} μP")

This prints the following:

.. testoutput::

Nitrogen gas properties at 773 K and 101,325 Pa
density 0.4416 kg/m³
viscosity 363.82 μP

This example uses the ``ChemicalEquation`` class to get properties of the reactants and products from a given chemical equation.

Expand All @@ -32,7 +42,7 @@ This example uses the ``ChemicalEquation`` class to get properties of the reacta
ce = cm.ChemicalEquation('2 HCl + 2 Na -> 2 NaCl + H2')
ce.is_balanced()
# The returns True for balanced equation
# This returns True for balanced equation
ce.rct_properties
# This returns a dataframe of the reactant properties
Expand Down

0 comments on commit 2844137

Please sign in to comment.