Git Product home page Git Product logo

nedtaylor / athena Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 2.0 1.36 MB

A Fortran-based feed-forward neural network library. Whilst this library currently has a focus on 3D convolutional neural networks (CNNs), it can handle most standard hidden layer forms of neural networks, with the plan to integrate more.

License: MIT License

CMake 3.06% Fortran 94.12% Makefile 2.02% Python 0.81%
convolution feed-forward-neural-networks fortran machine-learning neural-network convolutional-neural-networks cnn

athena's Introduction

MIT workflow Latest Release Downloads status FPM CMAKE GCC compatibility Coverage

athena

by Ned Thaddeus Taylor

ATHENA (Adaptive Training for High Efficiency Neural network Applications) is a Fortran library for developing and handling neural networks (with a focus on convolutional neural networks).

New Repository Location

This repository has been migrated from the University of Exeter GitLab to GitHub to facilitate community interaction and support. The latest version, updates, and collaboration now take place on this GitHub repository.

GitLab Repository (Archived): https://git.exeter.ac.uk/hepplestone/athena

Why the Migration?

It was decided that this project should be migrated to allow for better community support (i.e. allowing community users to raise issues). All information has been ported over where possible. Issues have not been migrated over, these can be found in the old repository. Releases prior to 1.2.0 have not been migrated over, but they can still be found as tags in this repository.


Statement of need

The ATHENA library leverages Fortran's strong support of array arithmatics, and its compatibility with parallel and high-performance computing resources. Additionally, there exist many improvements made available since Fortran 95, specifically in Fortran 2018 (Reid 2018) (and upcoming ones in Fortran 2023), as well as continued development by the Fortran Standards committee. All of this provides a clear incentive to develop further libraries and frameworks focused on providing machine learning capabilities to the Fortran community.

While existing Fortran-based libraries, such as neural-fortran (Curcic 2019), address many aspects of neural networks, ATHENA provides implementation of some well-known features not currently available within other libraries; these features include batchnormalisation, regularisation layers (such as dropout and dropblock), and average pooling layers. Additionally, the library provides support for 1, 2, and 3D input data for most features currently implemented; this includes 1, 2, and 3D data for convolutional layers. Finally, the ATHENA library supports many convolutional techniques, including various data padding types, and stride.

One of the primary intended applications of ATHENA is in materials science, which heavily utilises convolutional and graph neural networks for learning based on charge densities and atomic structures. Given the unique data structure of atomic configurations, specifically their graph-based nature, a specialised API must be developed to accommodate these needs.

References

Documentation

ATHENA is distributed with the following directories:

Directory Description
example/ A set of example programs utilising the ATHENA library
src/ Source code
tools/ Additional shell script tools for automating learning
test/ A set of test programs to check functionality of the library works after compilation

For extended details on the functionality of this library, please check out the wiki

NOTE: There currently exists no manual document. This will be included at a later date

Setup

The ATHENA library can be obtained from the git repository. Use the following commands to get started:

  git clone https://github.com/nedtaylor/athena.git
  cd athena

Dependencies

The library has the following dependencies:

  • A Fortran compiler (compatible with Fortran 2018 or later)
  • fpm or CMake for building the library

The library has been developed and tested using the following compilers:

  • gfortran -- gcc 13.2.0
  • ifort -- Intel 2021.10.0.20230609
  • ifx -- IntelLLVM 2023.2.0

Tested compilers

The library has also been tested with and found to support the following libraries:

  • gfortran -- gcc 12.3

Building with fpm

The library is set up to work with the Fortran Package Manager (fpm).

Run the following command in the repository main directory:

  fpm build --profile release

Testing with fpm

To check whether ATHENA has installed correctly and that the compilation works as expected, the following command can be run:

  fpm test --profile release

This runs a set of test programs (found within the test/ directory) to ensure the expected output occurs when layers and networks are set up.

Building with cmake

Run the following commands in the directory containing CMakeLists.txt:

  mkdir build  
  cd build  
  cmake [-DCMAKE_BUILD_TYPE="optim;mp"] ..  
  make install  

This will build the library in the build/ directory. All library files will then be found in:

  ${HOME}/.local/athena

Inside this directory, the following files will be generated:

  include/athena.mod
  lib/libathena.a

Testing with cmake

To check whether ATHENA has installed correctly and that the compilation works as expected, the following command can be run:

  ctest

This runs a set of test programs (found within the test/ directory) to ensure the expected output occurs when layers and networks are set up.

Examples

After the library has been installed, a set of example programs can be compiled and run to test the capabilities of ATHENA on the MNIST dataset. Some of the examples can be run as-is, and do not require external databases. For those that require the MNIST (a set of 60,000 hand-written numbers for training and 10,000 for testing, 0-9) dataset (i.e. 'example/mnist_' directories ), the dataset must first be downloaded. The example program has been developed to accept a text-based format of the MNIST dataset. The .txt database that these examples have been developed for can be found here: https://github.com/halimb/MNIST-txt/tree/master

The link to the original MNIST database is: http://yann.lecun.com/exdb/mnist/

NOTE: For the mnist examples, the MNIST dataset must be downloaded. By default, the database is expected to be found in the directory path ../../DMNIST. However, this can be chaned by editing the following line in the example/mnist[_VAR]/test_job.in file to point to the desired path:

  dataset_dir = "../../DMNIST"

Running examples using fpm

Using fpm, the examples are built alongside the library. To list all available examples, use:

  fpm run --example --list

To run a particular example, execute the following command:

  fpm run --example [NAME] --profile release

where [NAME] is the name of the example found in the list.

Running examples manually

To compile and run the examples, run the following commands in the directory containing CMakeLists.txt:

  cd example/mnist
  make build optim [FC=FORTRAN-COMPILER]
  ./bin/athena_test -f test_job.in

After the example program is compiled, the following directories will also exist:

Directory Description
example/mnist/bin/ Contains binary executable
example/mnist/obj/ Contains module/object files (non-linked binary files)

The example will perform a train over the MNIST dataset. Once complete, it will print its weights and biases to file, and test the trained network on the training set. The output from this can then be compared to the file expected_output_COMPILER.txt.

In the tools/ directory, there exist scripts that take utilise the wandb python package (Weights and Biases, a machine learning data tracker). Wandb is a Python module and, as such, a Python interface has been provided to call and run the Fortran example. The Python interface then reads the Fortran output files and logs the results to the wandb project.

Example wandb project link: https://wandb.ai/ntaylor/cnn_mnist_test/overview?workspace=user-ntaylor

How-to

To call/reference the ATHENA library in a program, include the following use statement at the beginning of the necessary Fortran file: use athena

During compilation, include the following flags in the compilation (gfortran) command:

-I${HOME}/.local/athena/include -L${HOME}/.local/athena/lib -lathena

Developers

  • Ned Thaddeus Taylor

Contributing

Please note that this project adheres to the Contributing Guide. If you are interested in contributing to this project, please contact Ned Taylor.

License

This work is licensed under an MIT license.

Code Coverage

Automated reporting on unit test code coverage in the README is achieved through utilising the cmake-modules and dynamic-badges-action projects.

Files

Source file Description
src/athena.f90 the module file that imports all necessary user-accessible procedures
src/lib/mod_accuracy.f90 accuracy calculation procedures
src/lib/mod_activation.f90 generic node activation (transfer) setup
src/lib/mod_activation_[NAME].f90 [NAME] activation method
src/lib/mod_base_layer.f90 abstract layer construct type
src/lib/mod_base_layer_sub.f90 base layer submodule
src/lib/mod_clipper.f90 gradient clipping procedures
src/lib/mod_constants.f90 a set of global constants used in this code
src/lib/mod_container.f90 layer container construct for handling multiple layers in a network
src/lib/mod_container_sub.f90 layer container submodule
src/lib/mod_[NAME]_layer.f90 [NAME] layer-type
src/lib/mod_initialiser.f90 generic kernel (and bias) initialiser setup
src/lib/mod_initialiser_[NAME].f90 [NAME] kernel initialisation method
src/lib/mod_loss.f90 loss and corresponding derivatives calculation procedures
src/lib/mod_lr_decay.f90 learning rate decay procedures
src/lib/mod_metrics.f90 training convergence metric derived type and procedures
src/lib/mod_misc.f90 miscellaneous procedures
src/lib/mod_misc_ml.f90 miscellaneous machine learning procedures
srcs/lib/mod_network.f90 neural network derived type and procedures
srcs/lib/mod_network_sub.f90 network submodule
src/lib/mod_normalisation.f90 data normalisation procedures
src/lib/mod_optimiser.f90 learning optimisation derived type and procedures
src/lib/mod_random.f90 random number procedures
src/lib/mod_tools_infile.f90 tools to read input files
src/lib/mod_types.f90 neural network-associated derived types
Additional file Description
CHANGELOG human-readable athena codebase version history
CMakeLists.txt the makefile used for compiling the library
CONTRIBUTING.md Guidelines for organisation of athena codebase
fpm.toml Fortran Package Manager (fpm) compilation file
LICENSE licence of ATHENA code
README.md a readme file with a brief description of the code and files
TODO todo-list in addition to useful machine learning and fortran references
cmake/CodeCoverage.cmake cmake-modules file to automate unit test coverage reporting
example/example_library Utility library shared between the examples
example/[NAME]/expected_output.txt expected output from executing [NAME] example program
example/[NAME]/test_job.in input file for [NAME] example program
example/[NAME]/src source directory for [NAME] example program
test/test_[NAME]__.f90_ [NAME] test program to check library expected functionality
tools/coverage_badge.py script to extract code coverage percentage from GitHub Action
tools/sweep_init.py script to initialise wandb sweep
tools/sweep_train.py script to perform training and log learning to wandb
tools/template.in input file for program in test/bin/ (once compiled)
tools/wandb-metadata.json metadata defining default plots on wandb website

athena's People

Contributors

milancurcic avatar nedtaylor avatar nedttaylor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

athena's Issues

gfortran-11.4 Internal Compiler Error building test_network.f90

When issuing fpm test --profile release:

...
test_dropblock3d_layer.f90             done.
test_network.f90                       failed.
[ 63%] Compiling...
f951: internal compiler error: Segmentation fault
0x74e33f24251f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x74e33f229d8f __libc_start_call_main
        ../sysdeps/nptl/libc_start_call_main.h:58
0x74e33f229e3f __libc_start_main_impl
        ../csu/libc-start.c:392
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
<ERROR> Compilation failed for object " test_test_network.f90.o "
<ERROR> stopping due to failed compilation
STOP 1

I can see that the README states that the lowest tested gfortran is v13, and that the library is possibly not expected to build with lower version. Reporting here nevertheless to document the issue.

Part of openjournals/joss-reviews#6492

Implement message passing neural network

Implement the generalised form of message passing neural networks, as detailed in "Neural Message Passing for Quantum Chemistry" by Gilmer et al.

https://dl.acm.org/doi/10.5555/3305381.3305512

Implement at least one exact method of message passing neural network to show functionality and how others can extend it themselves.

This does require adding dependency of the library to a graph derived type module, which should be distinct from athena.

Convert from real12 to compilable real precision

This will remove the need for users to use real12 types, improving compatibility.

This will also allow users on compilation choose precision, and make it more inline with industry standards.

add topic cnn

I suggest adding the topic cnn in the About section

1D pooling layers

Need to implement 1D pooling layers for average and maximum techniques.

Some tests fail with ifort-2021.10 and ifx-2023.2

Based off the main branch, the library now builds fine with both ifort and ifx (thanks!). Running the tests, however, some fail. There are more failures with ifort than with ifx. This is built with fpm and the debug profile which enables various diagnostics. Running in the release mode simply turns these into segfaults. So I attach the outputs of

FPM_FC=ifort fpm test >& athena-fpm-test-log-ifort-2021.10.txt
FPM_FC=ifx fpm test >& athena-fpm-test-log-ifx-2023.2.txt

My full compiler versions are:

ifort --version
ifort (IFORT) 2021.10.0 20230609
Copyright (C) 1985-2023 Intel Corporation.  All rights reserved.

ifx --version
ifx (IFX) 2023.2.0 20230721
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

athena-fpm-test-log-ifx-2023.2.txt
athena-fpm-test-log-ifort-2021.10.txt

In support of openjournals/joss-reviews#6492

Provide clear reference to neural-fortran

This issue can include a list of files where inspiration has been taken (or neural-fortran has been used as a template) for procedures and modules.

Feel free to comment here with files that need correct attributing.

Files requiring clear attributing:

  • example/simple/src/main.f90
  • example/sine/src/main.f90
  • get_num_params_* procedure
  • get_params_* procedure
  • set_params_* procedure
  • get_gradients_* procedure
  • set_gradients_* procedure
  • get_output_* procedure
  • src/lib/mod_optimiser.f90 module

Files where attributing needs to be discussed (these are not copies of neural-fortran, but concepts may be shared):

  • input layers
  • flatten layers

Change misc module name

Likely change it to misc_athena.
Same with constants, change it to constants_athena.

This should reduce conflict issues with personal codes.

Return value of function not defined lr_decay

Related to #21, warning when compiling with ifx.

ifx 2023.2.0 20230721

Warning does not occur in compilation of mod_lr_decay.f90. Warning only arises when a module or program uses the learning_rate_decay module (found in file mod_lr_decay.f90).

(base) [ntt203@phy-cdt16 build]$ make
[  0%] Building Fortran object CMakeFiles/athena.dir/src/lib/mod_constants.f90.o
...
[ 31%] Building Fortran object CMakeFiles/athena.dir/src/lib/mod_input4d_layer.f90.o
[ 32%] Building Fortran object CMakeFiles/athena.dir/src/lib/mod_lr_decay.f90.o
[ 33%] Building Fortran object CMakeFiles/athena.dir/src/lib/mod_maxpool2d_layer.f90.o
...
[ 37%] Building Fortran object CMakeFiles/athena.dir/src/lib/mod_optimiser.f90.o
/tmp/ifx16713391811BbRBG/ifxItJuj9.i90: warning #6178: The return value of this FUNCTION has not been defined.   [LR_DECAY]
[ 37%] Building Fortran object CMakeFiles/athena.dir/src/lib/mod_network.f90.o
...
[ 40%] Building Fortran object CMakeFiles/athena.dir/src/athena.f90.o
/tmp/ifx0214165105ctfpsh/ifx9j5FEk.i90: warning #6178: The return value of this FUNCTION has not been defined.   [LR_DECAY]
[ 41%] Building Fortran object CMakeFiles/athena.dir/src/lib/mod_base_layer_sub.f90.o
...
[ 44%] Linking Fortran static library libathena.a
[ 44%] Built target athena

Statement of need in the docs

Following the checklist, can you point me to, or add if not present, the statement of need to the docs (ideally near the top of the README.md):

A statement of need: Do the authors clearly state what problems the software is designed to solve and who the target audience is?

Part of openjournals/joss-reviews#6492

CONTRIBUTING.md was largely copied from neural-fortran

CONTRIBUTING.md, as of 0d3f02b, seems copied from https://github.com/modern-fortran/neural-fortran/blob/main/CONTRIBUTING.md and only edited to change the occasional wording and to account for different features of the library. For example, the layout, sections, and sentence structures and semantics are almost exactly the same.

Personally, as creator of neural-fortran and its CONTRIBUTING.md doc, I don't mind as long as you reference it at the top (e.g. "This document was adapted from https://github.com/modern-fortran/neural-fortran/blob/main/CONTRIBUTING.md", or similar). But given that the software and its docs are part of the submission itself, which is expected to be original, this may be problematic.

This CONTRIBUTING.md is not the kind of generic CONTRIBUTING guide for community projects (in which case a copied CONTRIBUTING.md may not be a problem), but bespoke and very specific to the library.

@HaoZeke what's your take or is there a JOSS guideline for this? If it's problematic, a simple solution could be to simply rewrite CONTRIBUTING.md in original language.

To be clear, I don't think this was intentional but merely an honest omission by @nedtaylor.

I see similar issues with parts of the code, but I'll open separate issues for those.

Part of openjournals/joss-reviews#6492

Add more normalisation methods

Include more methods of normalisation

  • Change name of normalisation procedures
  • Change 'norm' argument in renormalise_sum
  • robust scaling (uses IQR instead of range from min-max scaling)
  • log transformation

Naming of batchnorm1d

In PyTorch, batchnorm1d layers can either handle 2D or 3D data (where 2D input shape is (B, C) and 3D input shape is (B, C, L)).

B = batch size
C = number of channels
L = number of input features within the channel).

In our current implementation, ATHENA currently only handles 2D datatype.

I cannot currently see a way to make it handle both shapes (other than through the previously considered method of all data simply being 1D). As such, should there just be batchnorm0d and batchnorm1d?

https://pytorch.org/docs/stable/generated/torch.nn.BatchNorm1d.html

Missing manual

The library currently has no PDF manual.

  • Create PDF manula
  • add doc/ directory

Convert di and output to rank 2

If di and output are rank 2 allocatable arrays of the abstract type base_layer_type, then they can be accessible everywhere. This means that we cam remove many select case statements.

Error compiling mod_base_layer.f90 with ifort and ifx

With ifort-2021.10:

mod_base_layer.f90                     failed.
[ 18%] Compiling...
././src/lib/mod_base_layer.f90(117): error #6118: The interface block containing the separate interface body must not be abstract.
     module subroutine initialise(this, input_shape, batch_size, verbose)
-----^
/tmp/ifort9QfSWv.i90(424): catastrophic error: Too many errors, exiting
compilation aborted for ././src/lib/mod_base_layer.f90 (code 1)
<ERROR> Compilation failed for object " src_lib_mod_base_layer.f90.o "
<ERROR> stopping due to failed compilation
STOP 1

With ifx-2023.2:

mod_base_layer.f90                     failed.
[ 18%] Compiling...
././src/lib/mod_base_layer.f90(117): error #6118: The interface block containing the separate interface body must not be abstract.
     module subroutine initialise(this, input_shape, batch_size, verbose)
-----^
/tmp/ifx15633005958Xufq1/ifxtP3YAF.i90(424): catastrophic error: Too many errors, exiting
compilation aborted for ././src/lib/mod_base_layer.f90 (code 1)
<ERROR> Compilation failed for object " src_lib_mod_base_layer.f90.o "
<ERROR> stopping due to failed compilation
STOP 1

Part of openjournals/joss-reviews#6492

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.