LoginSignup
3
2

More than 3 years have passed since last update.

Singularityのインストールと実行をしてみた

Last updated at Posted at 2019-09-22

Singularityとは

ユーザーが自身の計算環境を完全に再現し,保持できるようにした新しい Linux コンテナ.
(引用:https://www.hpc.co.jp/product/software/singularity/)

詳しい内容はこちらにあるので適宜参照してください.
https://qiita.com/mkt3/items/b9f86f5ddf9eb0f43608

Singularityを使ってみよう(概要)

以下の手順で進めていきます.

  1. Singularityをインストール
  2. Singularityを実行

今回試した環境は以下の通りです.
OS: Ubuntu 18.04 LTS
CPU: i3-4130 3.40GHz
メモリ: 16GB

1. Singularityをインストール

Singularityのインストールはこちらの記事を参考にしています.
https://qiita.com/biosugar0/items/837a8f87394ab0d67765

★Singularityはgo言語を必要とするので、インストールしていない場合は以下のサイトを参考にしてから進めてください.
https://qiita.com/a210/items/aa98ebfa847fb881b1a5

$ sudo apt update
$ sudo apt -y upgrade
$ sudo apt install -y git automake libtool make squashfs-tools libarchive-dev
$ git clone https://github.com/singularityware/singularity.git
$ cd singularity
$ ./mconfig
$ cd builddir/
$ make
$ sudo make install
$ singularity version

※以下のメッセージが出たら次のように対応してください.

unable to find the cryptsetup program, is the package cryptsetup-bin installed?

$ sudo apt install cryptsetup-bin

最後のバージョン確認が出来ればおkです.

2. Singularityを実行

前の記事で取り上げた「OpenFace」のDocker Hubを用いて説明します.
(別に他のimageでも問題ありません.)
以下のコードを実行すると,Singularityが動作します.

$ singularity shell --nv docker://algebr/openface:latest

■説明
--nv:コンテナ内でコンテナ外のGPUを利用可能とするオプション

※一回目はdocker hubからimageを取得し,「.sif」ファイルにする処理があるので少し時間はかかります.

以下のような形になれば問題ないと思います.

Singularity openface_latest.sif:~>

まとめ

今回はSingularityをインストールし,実行もしてみました.
まだ触って日が浅いので,間違いがあればご指摘して頂きますと幸いです.

追記 2019/0926

Singularityを使えるようになったのはいいけど,必要に応じてパッケージを適宜追加したい.そんな時には,オプションに「--sandbox」を追加してビルドすれば書き込み可能コンテナが作れます.

今回はこちらの記事を参考にしています.
https://qiita.com/HoriThe3rd/items/6982247ac0f612d0474a

例として,chainerコンテナをビルドしてみましょう.

$ sudo singularity build --sandbox chainer_box docker://chainer/chainer:latest-python3

これでchainerコンテナのsandboxがディレクトリとして作成されます.
※コンテナ名(chainer_box)は任意の名前で問題ありません.

このsandboxを書き込み可能でアクセスするときは以下のコードを実行します.

$ sudo singularity shell --writable chainer_box

アクセスできたら,いよいよ必要なパッケージをインストールします.
今回は音声解析でよく用いられる「librosa」をインストールしていきます.

Singularity chainer_box:~> pip3 install librosa
Traceback (most recent call last):
  File "/usr/bin/pip3", line 11, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib/python3.5/locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

おそらくこのようなエラーが出てくるので,以下のコードで対応します.

Singularity chainer_box:~> export LC_ALL=C

「export LC_ALL=C」を実行したあとに,再度librosaをインストールしてください.

その後で以下のコードを順に実行しましょう.

Singularity chainer_box:~> apt-get update
Singularity chainer_box:~> apt-get install libsndfile1-dev

最後にPythonを起動してlibrosaがimportできるかを確認します.

Singularity chainer_box:~> python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import librosa
>>> 

問題なくimportしているので,ちゃんとパッケージを追加することが出来ました.

参考文献

https://qiita.com/biosugar0/items/837a8f87394ab0d67765
https://hub.docker.com/r/algebr/openface/tags
https://github.com/sylabs/singularity-userdocs/issues/211
https://qiita.com/daikumatan/items/a1f442777f9b7bc13112
https://qiita.com/mkt3/items/b9f86f5ddf9eb0f43608
https://sc.ddbj.nig.ac.jp/ja/guide/software/singularity
https://qiita.com/a210/items/aa98ebfa847fb881b1a5
https://qiita.com/kon_yu/items/8ac350f3951f8534c931
https://improve-future.com/python-caution-on-scikits-audiolab-installation.html
https://stackoverflow.com/questions/36394101/pip-install-locale-error-unsupported-locale-setting/36394262
https://qiita.com/HoriThe3rd/items/6982247ac0f612d0474a

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2