SOPT is an open-source C++
package available under the license below. It performs Sparse OPTimisation using state-of-the-art convex optimisation algorithms. It solves a variety of sparse regularisation problems, including the Sparsity Averaging Reweighted Analysis (SARA) algorithm.
SOPT also has several MPI wrappers that can be adapted for computational distirbution of various linear operators and convex optimisation algorithms. Wavelet Operators with SOPT also support multi-threading through OpenMP.
SOPT is written in C++
primarily but also contains partial and prototyped Matlab implementations of various algorithms.
SOPT is largely provided to support the PURIFY package, a companion open-source code to perform radio interferometric imaging, also written by the authors of SOPT. For further background please see the reference section.
This documentation outlines the necessary and optional dependencies upon which SOPT should be built, before describing installation and testing details and Matlab support. Contributors, references and license information then follows.
SOPT is mostly written in C++17
. Pre-requisites and dependencies are listed in following and minimal versions required are tested against Travis CI
meaning that they come natively with OSX and the Ubuntu Trusty release. These are also the default ones fetched by CMake
.
C++
minimal dependencies:
C++
.C++
linear algebra. Downloaded automatically if absent.C++
unit-testing framework only needed for testing. Downloaded automatically if absent.C++
micro-benchmarking framework only needed for benchmarks. Downloaded automatically if absent.Conan is a C++ package manager that helps deal with most of the C++ dependencies as well as the SOPT installation:
Once the mandatory dependencies are present, git clone
from the GitHub repository:
git clone https://github.com/astro-informatics/sopt.git
Then, the program can be built using conan:
cd /path/to/code
mkdir build
cd build
conan install .. -of . --build missing
conan build .. -of .
Things to note:
To install in directory INSTALL_FOLDER
, add the following options to the conan build command:
conan build .. -of INSTALL_FOLDER
CMake build options should be passed as options to conan install
using the -o
flag with a value on
or off
.
Possible options are:
For example, to build with both MPI and OpenMP on you would use
conan install .. -of . --build missing -o openmp=on -o dompi=on
conan build .. -of .
If the dependencies are already available on your system, you can also install SOPT manually like so
cd /path/to/code
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=${PWD}/../local
make -j
make -j install
On MacOS, you can also install most of the dependencies with Homebrew e.g.
brew install libtensorflow eigen tiff catch2
Note that the ONNXruntime interface is currently only supported when compiling with Clang on MacOS, but not with g++
You can set commonly used options, choices of compilers etc. in a
conan profile.
You can list profiles available on your system using conan profile list
and
select the profile you want to use with conan install
with
conan install .. -pr my_profile
.
CMake build options can also be added to the profile under [options]
.
Here is an example of a conan profile for building with a homebrew installed gcc 11 on MacOS.
[settings]
os=Macos
os_build=Macos
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
To check everything went all right, run the test suite:
cd /path/to/code/build
ctest .
Machine-learning models are supported via the ONNXruntime interface. Nearly all modern ML toolkits allow to export their trained models into the ONNXruntime format using Python.
Install translation packages e.g. using pip
:
pip install onnx
pip install onnxscript
PyTorch models can be exported to ONNXruntime like so
import torch
torch_model = ... # PyTorch model based on torch.nn
torch_input = torch_input = torch.randn(256, 256) # model input tensor
torch.onnx.export(torch_model,
torch_init,
'model_name.onnx', # output file name
export_params=True, # store trained param weights
opset_version=11, # ONNX version to export the model to
do_constant_folding=True, # optmise using pre-computed constant nodes
input_names=['input'],
output_names=['ouput'],
dynamic_axes={'input' : {0 : 'batch_size'},
'output' : {0 : 'batch_size'}})
Tensorflow models can be exported to ONNXruntime like so
python -m tf2onnx.convert
--saved-model model_name.pb
--output model_name.onnx
--opset 11
--inputs input0:0
--extra_opset StatefulPartitionedCall:0
Unknown TF input dimensions can be specified e.g. using --inputs 'input0:0[1,256,256,1]'
.
After the export, load the model and verify that it's well formed like so
import onnx
onnx_model = onnx.load("model_name.onnx")
onnx.checker.check_model(onnx_model)
print( onnx_model.graph.input )
Netron is a useful online tool to help visualise the model.
A separate Matlab implementation is provided with SOPT.
This implementation includes some (but not all) of the optimisation algorithms implemented in the C++
code, including the SARA algorithm.
The Matlab implementation is contained in the matlab directory.
This is a stand-alone implementation and does not call any of the C++
code.
In future, Matlab interfaces to the C++
code may also be included in SOPT.
See matlab/README.txt
for an overview of the Matlab implementation.
The stand-alone Matlab implementation is also self-documenting;
corresponding documentation can be found in matlab/doc
.
We thank Gilles Puy for contributing to this Matlab implementation.
Check the [contributors](@ref sopt_contributors) page (github).
If you use SOPT for work that results in publication, please reference the webpage and our related academic papers:
SOPT: Sparse OPTimisation package Copyright (C) 2013-2024
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details (LICENSE.txt).
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
For any questions or comments, feel free to contact Jason McEwen, or add an issue to the issue tracker.
The code is given for educational purpose. For the Matlab
version of the code see the folder matlab.