Skip to content

Materials for a workshop showing how to use the FTorch library to couple PyTorch and Fortran

License

Notifications You must be signed in to change notification settings

Cambridge-ICCS/FTorch-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation








FTorch Workshop

GitHub CC BY-NC-SA 4.0

This repository contains documentation, resources, and code for the a workshop teaching use of the ICCS FTorch library for coupling PyTorch models to Fortran code. The session has been designed and delivered by Jack Atkinson (@jatkinson1000) and has been taught at the ICCS summer schools.
All materials are available such that individuals can cover the course in their own time.

Contents

Learning Objectives

The key learning objective from this workshop could be simply summarised as:
Provide the ability to couple PyTorch models to Fortran using FTorch.

However, more specifically we aim to:

  • provide a deeper understanding of Torch models and the libtorch library,
  • introduce FTorch and it's aims and benefits,
  • teach users the full pipeline of taking a PyTorch model and coupling it to a Fortran code, and
  • highlight best practices and efficient use when doing the above.

Teaching Material

Slides

The slides for this workshop can be viewed on the ICCS Summer School Website:

The slides are generated from markdown using quarto. The raw markdown and html files can be found in the slides directory.

Exercises

The exercises for the course can be found in the exercises directory.

Preparation and prerequisites

To get the most out of the session we assume a basic understanding in a few areas and for you to do some preparation in advance. Expected knowledge is outlined below, along with resources for reading if you are unfamiliar.

Python

The course uses some elements of Python and assumes some basic knowledge of the ecosystem. This includes:

  • use of a python virtual environment,
  • installation of dependencies, and
  • running python scripts from the command line.

Machine Learning and PyTorch

Whilst we are using PyTorch and neural networks in this course we will not be teaching any formal concepts.

Fortran

The key objective of this course is to call PyTorch code from within Fortran. However, expert knowledge is not a prerequisite. Rather, we will assume that you are comfortable reading Fortran code and familiar with the basic concepts of the language (variables, subroutines, modules etc.) To this end Fortran-Lang provide an excellent quickstart tutorial.

Preparation

In preparation for the course please ensure that your computer contains the following:

Note for Windows users: We strongly advise using the Windows Subsystem for Linux (WSL) for this workshop. If you wish to proceed on native Windows please follow the specific FTorch guidance for Windows Users to prepare a system.
We have linked suitable applications for Windows in the above lists, though you may wish to refer to Windows' getting-started with python information for a complete guide to getting set up.

If you require assistance or further information with any of these please reach out to us before a training session.

Installation and setup

1. Clone or fork the repository

Navigate to the location you want to install this repository on your system and clone via https by running:

git clone https://github.com/Cambridge-ICCS/FTorch-workshop.git

This will create a directory FTorch-workshop/ with the contents of this repository.

Please note that if you have a GitHub account and want to preserve any work you do we suggest you first fork the repository and then clone your fork. This will allow you to push your changes and progress from the workshop back up to your fork for future reference.

2. Create a virtual environment

Before installing any Python packages it is important to first create a Python virtual environment. This provides an insulated environment inside which we can install Python packages without polluting the operating system's Python environment.

If you have never done this before don't worry: it is very good practise, especially when you are working on multiple projects, and easy to do.

python3 -m venv venv

This will create a directory called venv/ containing software for the virtual environment. To activate the environment run:

source venv/bin/activate

You can now work on python from within this isolated environment, installing packages as you wish without disturbing your base system environment.

When you have finished working on this project run:

deactivate

to deactivate the venv and return to the system python environment.

You can always boot back into the venv as you left it by running the activate command again.

3. Install dependencies

It is now time to install the dependencies for our code, for example PyTorch. The project has been packaged with a pyproject.toml so can be installed in one go. From within the root directory in a active virtual environment run:

pip install .

This will download the relevant dependencies into the venv as well as setting up the datasets that we will be using in the course.

License

The code materials in this project are licensed under the MIT License.

The teaching materials are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

Contribution Guidelines and Support

If you spot an issue with the materials please let us know by opening an issue here on GitHub clearly describing the problem.

If you are able to fix an issue that you spot, or an existing open issue please get in touch by commenting on the issue thread.

Contributions from the community are welcome. To contribute back to the repository please first fork it, make the neccessary changes to fix the problem, and then open a pull request back to this repository clerly describing the changes you have made. We will then preform a review and merge once ready.

If you would like support using these materials, adapting them to your needs, or delivering them please get in touch either via GitHub or via ICCS.

About

Materials for a workshop showing how to use the FTorch library to couple PyTorch and Fortran

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published