Skip to main content

SVETlANNa is an open-source Python library for simulation of free-space optical set-ups and neuromorphic systems such as Diffractive Neural Networks.

Project description

en ru

SVETlANNa

SVETlANNa is an open-source Python library for simulation of free-space optical set-ups and neuromorphic systems such as Diffractive Neural Networks. It is primarily built on the PyTorch framework, leveraging key features such as tensor-based computations and efficient parallel processing. At its core, SvetlANNa relies on the Fourier optics, supporting multiple propagation models, including the Angular spectrum method and the Fresnel approximation.

There is a supporting github project SVETlANNa.docs containing numerous application examples in the Jupyter notebook format.

The name of the library is composed of the Russian word "svet", which is the "light" in English and the abbreviation ANN standing for an artificial neural network, and simultaneously the whole word sounds like a Russian female name Svetlana.

Abbreviations

NN - Neural Network

ANN - Artificial Neural Network

ONN - Optical Neural Network

DONN - Diffractive Optical Neural Network

DOE - Diffractive Optical Element

SLM - Spatial Light Modulator

Features

  • based on the PyTorch
  • forward propagation models include the Angular spectrum method and the Fresnel approximation
  • possibility to solve the classical DOE/SLM optimization problem with the Gerchberg-Saxton and hybrid input-output algorithms
  • support for custom elements and optimization methods
  • support for various free-space ONN architectures including feed-forward NN, autoencoders, and recurrent NN
  • cross platform
  • full GPU aceleration
  • companion repository with numerous .ipynb examples
  • custom logging, project management, analysis, and visualization tools
  • tests for the whole functionality

Possible applications

  • modeling and optimization of optical systems and optical beams propagating in free space;
  • calculation of parameters of phase masks, DOEs and SLMs for both classical optical systems and neuromorphic optical computers;
  • modeling and optimization of parameters of ONN and DONN for problems of all-optical classification and prediction.

Recommended technical requirements:

  1. Intel Core i5 8400 / AMD Ryzen 5 1400 or higher;
  2. memory greater than 8 Gb;
  3. HDD/SSD space not less than 16 Гб (virtual enviroment takes about 6 Gb);
  4. for running on GPU you need an Nvidia card with CUDA support and memory not less than 2 Gb;
  5. OS Windows 10 or greater, or Linux with kernel 5.15 or greater;
  6. the library requires Python 3.11.

Installation, Usage and Examples

For usage there are two options, either run from the source or install from pip.

Installation From PyPI

pip install svetlanna

Running From Source

We reccomend first to install git in your system.

  1. Clone the repository:
  git clone https://github.com/CompPhysLab/SVETlANNa.git
  1. Move to the project dyrectory:
  cd SVETlANNa
  1. Create a virtual environment for Python 3.11 (see venv documentation) and activate it.
  2. Istall the Poetry (version 2.0.0 or greater):
  pip install poetry
  1. Install all depencies:
  poetry install --all-extras
  1. Install the PyTorch (check the instructions at the official cite). Choose options appropriate to your system. For running the library on a GPU you need to have an appropriate graphic card and a PyTorch version which supports this card.
  pip install torch

Running Tests

The tests can be executed when the library is running from source only. PIP istallation does not include tests.

NOTE: running tests requires at least 4 Gb of free memory.

To run tests, run the following command (within the activated virtual environment in the library folder)

  pytest

Documentation

Documentation

Running examples with library installation

Examples of various scenarios and setups are provided in the repository SVETlANNa.docs.

To run the example locally follow the instructions:

  1. Clone the repository (you should have an installed git):
  git clone https://github.com/CompPhysLab/SVETlANNa.docs.git
  1. Go to the project directory:
  cd SVETlANNa.docs

3.Create a virtual environment for Python 3.11 (see venv documentation) and activate it. All subsequent actions should be done within the activated environment. 4. Install the main library:

  pip install svetlanna
  1. Install the PyTorch (check the instructions at the official cite). Choose options appropriate to your system. For running the library on a GPU you need to have an appropriate graphic card and a PyTorch version which supports this card.
  2. If you do not have the Jupyter notebook in your system, install it:
  pip install notebook
  1. Install additional dependencies:
  pip install reservoirpy matplotlib tqdm requests av scikit-image py-cpuinfo gputil
  1. Run the Jupyter notebook:
  jupyter notebook

and open the page in your browser (see “Or copy and paste one of these URLs:” in a terminal window) 9. Go to the folder SVETlANNa.docs. Examples are grouped into subject subfolders in form of .ipynb files. To run them you need to open a file in the Jupyter notebook and run all code cells (key Shift+Enter).

Running exaples with SVETlANNa installed from source

  1. Clone the repository (you should have an installed git):
	git clone https://github.com/CompPhysLab/SVETlANNa.docs.git 

All subsequent actions should be done within the activated environment, which was used to install the SVETlANNa library from source. 2. If you do not have the Jupyter notebook in your system, install it:

  pip install notebook
  1. Install additional dependencies:
  pip install reservoirpy matplotlib tqdm requests av scikit-image py-cpuinfo gputil
  1. Run the Jupyter notebook:
  jupyter notebook

and open the page in your browser (see “Or copy and paste one of these URLs:” in a terminal window) 5. Go to the folder SVETlANNa.docs. Examples are grouped into subject subfolders in form of .ipynb files. To run them you need to open a file in the Jupyter notebook and run all code cells (key Shift+Enter).

Examples

Result of training the feed-forward optical neural network for the MNIST classification task: The image of the figure "8" is passed through a stack of 10 phase plates with adjusted phase masks. Selected regions of the detector correspond to different classes of figures. The class of the figure is identified by the detector region that measures the maximum optical intensity.

Examples of visualzation of optical set-ups and optical fields:

drawing

Example a of five-layer DONN trained to recognize numbers from the MNIST database:

drawing drawing drawing

Contributing

Contributions are always welcome!

See contributing.md for ways to get started.

Please adhere to this project's code of conduct.

Acknowledgements

The work on this repository was initiated within the grant by the Foundation for Assistance to Small Innovative Enterprises

Authors

License

Mozilla Public License Version 2.0

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

svetlanna-1.0.4.tar.gz (62.3 kB view details)

Uploaded Source

Built Distribution

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

svetlanna-1.0.4-py3-none-any.whl (79.7 kB view details)

Uploaded Python 3

File details

Details for the file svetlanna-1.0.4.tar.gz.

File metadata

  • Download URL: svetlanna-1.0.4.tar.gz
  • Upload date:
  • Size: 62.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for svetlanna-1.0.4.tar.gz
Algorithm Hash digest
SHA256 1f419c366f17e02354d9fdafa2943e6e678d2ae483412523dcff14a203bd5d5c
MD5 1707f77c86df07c78dfdc25cd7346092
BLAKE2b-256 a488a630ebc847a8fe8b8e185b46d373c1aad31018391546c10e52588fab3f80

See more details on using hashes here.

File details

Details for the file svetlanna-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: svetlanna-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 79.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for svetlanna-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5adeb5de1e643e808c727fd4bffb805bb01316dc3a0fd3d02bdfb63f3bdf6d61
MD5 bc9c023d0cc9c5cbab6b28dc08766cd2
BLAKE2b-256 4f6a9303a1331628643e18961e09b4d170ad37b359b6ab85c52a35f2e487cbb0

See more details on using hashes here.

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