Skip to main content

Syna is a lightweight machine learning framework inspired by DeZero.

Project description

Syna

PyPI - Version GitHub License PyPI - Python Version GitHub Actions Workflow Status

Syna is a lightweight machine learning framework inspired by DeZero. Built from scratch using only NumPy, it follows a define-by-run (dynamic computation graph) approach and includes a basic reinforcement learning framework.

Unlike most frameworks that implement reinforcement learning as a separate library, Syna provides everything in a single library.

Designed for beginners and researchers, Syna helps you learn the fundamentals of machine learning and the inner workings of frameworks like PyTorch. Performance is not the focus, and GPU support is intentionally omitted to keep the code simple and easy to understand.

Installation

Get the Syna Source

git clone https://github.com/sql-hkr/syna.git
cd syna
uv venv
source .venv/bin/activate
uv sync

Or, from PyPI:

uv add syna

[!IMPORTANT] To visualize the computation graph, you need to install Graphviz.

brew install graphviz # macOS
sudo apt install graphviz # Linux

Getting started

Computation Graph

Visualize the computation graph for the fifth derivative of tanh(x) with respect to x.

import syna
import syna.functions as F
from syna.utils import plot_dot_graph

x = syna.tensor(1.0)
y = F.tanh(x)
x.name = "x"
y.name = "y"
y.backward(create_graph=True)

iters = 4

for i in range(iters):
    gx = x.grad
    x.cleargrad()
    gx.backward(create_graph=True)

gx = x.grad
gx.name = "gx" + str(iters + 1)
plot_dot_graph(gx, verbose=False, to_file="tanh.svg")

The output graph is shown below.

RL (Deep Q-Network; DQN)

Solve CartPole-v1 using the DQN algorithm.

from syna.algo.dqn import DQNAgent
from syna.rl import Trainer

trainer = Trainer(
    env_name="CartPole-v1",
    num_episodes=300,
    agent=DQNAgent(
        lr=3e-4,
    ),
)
trainer.train()

API Reference

License

Syna is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

syna-0.2.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

syna-0.2.0-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file syna-0.2.0.tar.gz.

File metadata

  • Download URL: syna-0.2.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for syna-0.2.0.tar.gz
Algorithm Hash digest
SHA256 633659d966abc7f05f212d2a9611cbd430e9f932867fe6db569c610307c73c37
MD5 7cbf17cc1b923aa307ed198d1bed9bb7
BLAKE2b-256 48987b07df0d5fc05f9a8028a26ae47121d0f0a76a977849ab4e9c0c1cfddaae

See more details on using hashes here.

Provenance

The following attestation bundles were made for syna-0.2.0.tar.gz:

Publisher: python-publish.yml on sql-hkr/syna

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file syna-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: syna-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for syna-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a86fcb6931c0ac65d46ef76eb5977b4b501c1c3f382c5deb21687217ec5bbbf
MD5 02d15477bcddc23e0382bb935cf85de7
BLAKE2b-256 e4777105ea9444b45bff06ac58cf379d79f8ab73db975795b10fafeb1a30b0bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for syna-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on sql-hkr/syna

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page