/MathSo

Lecture on numeric

Primary LanguageJupyter NotebookMIT LicenseMIT

Build Status Binder Open In Colab

MathSo

Lecture on mathematical software:

  • python basics (Python as a pocket calculator, Operator precedence, Representation of numbers in Python, Functions, Vectors / arrays / Lists, Indexing, Array operators, Creating matrices)
  • [boolean arrays](notebook/Boolean Arrays.ipynb) (Functions of logical vectors, Elements of programming, Recursion)
  • [systems of linear equations](notebook/Systems of linear equations.ipynb) (Overdetermined systems, Underdetermined systems, Ill-conditioned systems, Logical operators, Logical vectors)
  • data input visualization (NumPy Array, Pandas data input, Visualization, Two-dimensional plots)
  • loops / input output (for loops vs. array sums, while loops, Input and output, String formatting)
  • visualization (Multiple plots, figure, subplot, Combining two subplots, plotting functions using fplot, discrete data plots, scatter, stairs, stem, log plots, error bar plots, pie and bar plots, histograms, polar plots, editing plots, saving, printing and exporting)
  • visualization 3d (Line plots, Scatter plots, Mesh (wireframe), Surface plots)

Lecture on numeric:

Prerequisit

GitHub CLI is required to clone repositories hosted on GitHub.com. Poetry is used for python packaging and dependency management. Pyenv lets you easily switch between multiple versions of Python.

macOS

via Homebrew

brew install gh
brew install poetry
brew install pyenv

Install

Our project is using python 3.9.7, so let's install it:

pyenv install 3.9.7

Go to your project folder and clone a GitHub repository locally.

gh repo clone OleBo/MathSo & cd MathSo
poetry install & poetry shell

The 'poetry install' reads the poetry.lock file from the current directory, processes it, and downloads and installs all the libraries and dependencies outlined in that file. If the file does not exist it will look for pyproject.toml and do the same.

The 'shell' command spawns a shell, according to the $SHELL environment variable, within the virtual environment. If one doesn’t exist yet, it will be created.

Using Notebooks

The notebook extensions can be installed. They need to be copied to the Jupyter data directory. Then, the installed notebook extensions can be enabled, either by using built-in Jupyter commands, or more conveniently by using the 'jupyter_nbextensions_configurator' server extension, which is installed as a dependency of this repo.

jupyter contrib nbextension install --user
jupyter nbextensions_configurator enable --user
jupyter nbextension enable toc2/main
jupyter nbextension enable collapsible_headings/main
jupyter nbextension enable highlight_selected_word/main
jupyter nbextension enable execute_time/ExecuteTime

Go to the notebooks folder and start Jupyter

jupyter notebook

Template and CI

The software development principles for this project are drawn from a medium article by Trace Smith and its template repository.

In the project root, the project code is organized into the main module, notebooks/, math_so/, additional executable scripts or helpers, scripts/, and unit or integration tests in tests/. We generally follow the convention of placing our main shared executable code within the main module. Scripts are meant to be ad-hoc utilities run from the command line which may be used in setting up datasets or otherwise. An additional directory could also be added here containing infrastructure specific code (e.g. AzureML, AWS, Airflow, etc.).

configuring the environment

In order to repoduce this framework we use

  • pyenv - for managing the Python environment
  • poetry - for managing required dependencies

continuous integration (CI)

The integration pipeline is configured to only run if code changes are being merged into the master branch. Thus, once a pull request is opened, the build will kick-off and the status of the run will be provided in the PR window opened in GitHub.

The build step will run the .travis.yml file located in the project repository which contains a series of commands to execute. Within this job, there are three tasks that will be checked:

  • unit tests,
  • code formatting and
  • code linting. Once the build is initiated from the opened pull request, you can monitor the runs in real-time.

unit tests

We will utilize pytest for writing and maintaining tests. The testing scripts should reside in the tests directory within the project root. pytest expects the file names to begin with test_ or end with _test.py. Here, we've adopted the naming convention test_<name-of-task>.py.

We will utilize pytest-cov to produce coverage results of your unit tests. Here, we can measure the percentage of the source code that the tests cover. To run pytest and pass the cov flag to output the coverage in order to have an idea on the completeness of the tests:

pytest cov=python_ml_template/utils/ tests/

auto formating

To make sure code being merged into the master branch is maintaining pep8 standards, we use autopep8. To format the source code files within the project, you can run this command:

vautopep8 --in-place --aggressive --recursive <path>

linting

We use flake8 to identify syntactical and stylistic problems in your source code.

flake8 path_to_check/