Skip to content

Commit

Permalink
Include several tests and minor fixes (#4)
Browse files Browse the repository at this point in the history
* 🧪 Tests: Update the tests

* 🧪 Tests: Add tests for the OptSolver

* ⚰️ Remove: Delete old and useless files

* 🩹 Patch: Add a simple addition. This allow us to add a initial value for the Variables

* 🧪 Tests: Add a fix to the `value` method, to now set the closes value limit when we're trying to update the value

* 📝 Docs: Add documentation for the gradient method

* ✏️ Typo: Fix minor typos

* 🐛 Bug: Fix a minor bug in the libraries for the engine

* 🧪 Test: Add tests for the gradient descent method

* 🔖 Tag: Bump version `0.3.1`

* ⬆️ Dependencies: Upgrade the lock for Cargo and poetry

* 👷 CI: Add different CI to evaluate the code

* ✅ Test: Evaluate the CI

* 🚚 Rename: Change the name to `action.yml`

* 👷 CI: Add tests for the CI

* ➕ Dependencies: Add pylint as dev dependency

* 👷 CI: Update the CI to install the python version `3.10`

* 💚 CI: Upgrade the general CI

* 💚 CI: Delete an useless command in th CI

* 👷 CI: Add a command for the tests

* 👷 CI: Add the `--release` flag in the Rust CI

* ⚡️ Improve: Improve the Rust code with minor changes

* 👷 CI: Add final line to the CI

* 👷 CI: Add an etra layer of evaluation in Rust CI
  • Loading branch information
ricardoleal20 authored Jul 17, 2024
1 parent d9f399b commit c31a45c
Show file tree
Hide file tree
Showing 22 changed files with 530 additions and 221 deletions.
27 changes: 27 additions & 0 deletions .github/actions/python_ci/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Python CI 🐍
description: CI that evaluates the Python linter

# ----------------------------------- #
# DEFINE THE STEPS #
# ----------------------------------- #

runs:
using: "composite"
steps:
- name: Checkout code 🔍
uses: actions/checkout@v2

- name: Set up Python 🐍
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies 🏗️
shell: bash
run: |
pip install poetry
poetry install
- name: Evaluate the linter ☢️
shell: bash
run: poetry run pylint pymath_compute/ --rcfile pyproject.toml
27 changes: 27 additions & 0 deletions .github/actions/rust_ci/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Rust CI 🦀
description: Action that check the Rust code using the built-in cargo check

# ----------------------------------- #
# DEFINE THE STEPS #
# ----------------------------------- #


runs:
using: "composite"
steps:
- name: Checkout code 🔍
uses: actions/checkout@v2

- name: Set up Rust 🦀
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Check Rust code 🩺
shell: bash
run: cargo check --release

- name: Build Rust code 🧱
shell: bash
run: cargo build --release
29 changes: 29 additions & 0 deletions .github/actions/tests_ci/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests CI 🧪
description: CI Action to perform the tests execution

# ----------------------------------- #
# DEFINE THE STEPS #
# ----------------------------------- #


runs:
using: "composite"
steps:
- name: Checkout code 🔍
uses: actions/checkout@v2

- name: Set up Python 🐍
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies 🏗️
shell: bash
run: |
pip install poetry
poetry install
poetry run maturin develop --release
- name: Run tests 🧪
shell: bash
run: poetry run pytest
31 changes: 31 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Continuous Integration Workflow 👾

# Controls when the action will run. We only want that this action to happens when
# we open a pull request that points to main
on:
pull_request:
branches:
- "main"

# ----------------------------------- #
# DEFINE THE JOBS #
# ----------------------------------- #

jobs:
rust_ci:
runs-on: ubuntu-latest
name: Run Rust CI 🦀
steps:
- uses: ricardoleal20/pymath_compute/.github/actions/rust_ci@ricardo/AddSolverTests

python_ci:
runs-on: ubuntu-latest
name: Run Python CI 🐍
steps:
- uses: ricardoleal20/pymath_compute/.github/actions/python_ci@ricardo/AddSolverTests

tests_ci:
runs-on: ubuntu-latest
name: Run tests 🧪
steps:
- uses: ricardoleal20/pymath_compute/.github/actions/tests_ci@ricardo/AddSolverTests
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [0.3.1] - 16/07/2024

### Added

- [Classifiers]: Add the classifiers for the project, including homepages and more stuff
- [Maturin]: Add information for the correct Rust/Python project be implemented
- [Tests]: Include the Engine and the solver tests
- [Variable]: Now, you can directly include the initial value of the variable in their definition
- [Variable]: Now, in the setter, the value set is going to be the closes bound if the expected value is outside the bound

### Fixed

- [Engine]: The engine now it updates the value using the setting method `value`, instead of going directly for the `_value`.

## [0.3.0] - 15/07/2024

### Added
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pymath_compute_engine"
version = "0.1.0"
name = "pymath_compute"
version = "0.3.1"
edition = "2021"

[dependencies]
Expand Down
84 changes: 76 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion pymath_compute/engine/optimization_methods.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,20 @@ def gradient_descent(
iterations: int,
tol: float,
) -> STATUS:
"""..."""
"""Gradient Descent implementation
This is a normal gradient descent implementation for a Python code.
The values of the variables are updated in each iteration of the
method, only if the old cost is better than the new cost.
Args:
- variables (list[Variable]): Variables given by the PyMath Module
- cost_method (Callable): Method to calculate the cost.
- var_step (float): Finite step to calculate the gradient
- learning_rate (float): The learning rate for the variables
- iterations (int): How many iterations are you going to run as max
- tol (float): The tolerance to know if you got an optimal
Returns:
- The status of the method
"""
23 changes: 22 additions & 1 deletion pymath_compute/methods/opt_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,28 @@ async def _gradient_descent( # pylint: disable=R0913
iterations: int = 1000,
tol: float = 1e-6,
) -> STATUS:
"""..."""
"""Gradient Descent implementation
This is a normal gradient descent implementation for a Python code.
The values of the variables are updated in each iteration of the
method, only if the old cost is better than the new cost.
Args:
- variables (list[Variable]): Variables given by the PyMath Module
- cost_method (Callable): Method to calculate the cost.
- var_step (float): Finite step to calculate the gradient
- learning_rate (float): The learning rate for the variables
- iterations (int): How many iterations are you going to run as max
- tol (float): The tolerance to know if you got an optimal
Returns:
- The status of the method
"""
if len(variables) < 2:
raise RuntimeError(
"This gradient method only works for more than 1 variable." +
"Try making your solution space more finite."
)
# Just call the gradient descent method from the engine
return gradient_descent(
variables,
Expand Down
Loading

0 comments on commit c31a45c

Please sign in to comment.