LoginSignup
2
2

More than 5 years have passed since last update.

MoodleでSTACKをインストールする

Last updated at Posted at 2017-06-27

Moodleで小テスト用数学プラグイン

Moodle用プラグインでSTACKと呼ばれる問題タイププラグインがあるが、インストールにコツが必要なので下記にまとめる。

前置き

以前にまとめたインストール手順に従ってMoodle 3.2.xをインストールしてあることを前提とする。

インストール手順

Maximaについての注意?事項

CentOS7 であればSTACKでサポートしているMaxima 5.38.0をyumでインストールすることもできるが、動作テストで一部エラーが出る…

# yum install -y maxima maxima-runtime-sbcl

# maxima
Maxima 5.38.0 http://maxima.sourceforge.net
using Lisp SBCL 1.3.11-1.el7
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) run_testsuite();
(略)
Error summary:
Errors found in /usr/share/maxima/5.38.0/tests/rtest_taylor.mac, problems:
(23 129)
2 tests failed out of 10,614 total tests.
Evaluation took:
  259.575 seconds of real time
  257.240750 seconds of total run time (254.945620 user, 2.295130 system)
  [ Run times consist of 8.383 seconds GC time, and 248.858 seconds non-GC time. ]
  99.10% CPU
  20,864 forms interpreted
  16,427 lambdas converted
  759,627,326,879 processor cycles
  1 page fault
  36,253,876,816 bytes consed

(%o0)                                done

実際にはSTACKの「評価関数の確認スクリプト」で全ての項目について特別な問題は出ないのだが、それ以外でSTACKの動作に影響する可能性を懸念してエラーの出ないような手順でインストールを行うことにする。
STACKのインストールドキュメントより推奨とされるMaxima 5.36.1をインストールし、LISPのインタプリタは動作速度からCLISPではなくSBCLを利用することとする。特にグラフ描画時の速度が圧倒的に高速(約10倍速い)。

SBCLのインストール

Maximaを動作させるためにSBCLをインストール。理由(後述)あってSBCL 1.2の最新(最終?)版である1.2.16をインストールする。
yum install sbcl だと 1.3.11 がインストールされるため手動で拾ってくる。

# yum install -y bzip2

# cd /usr/local/src/
# wget https://downloads.sourceforge.net/project/sbcl/sbcl/1.2.16/sbcl-1.2.16-x86-64-linux-binary.tar.bz2
# tar jxf sbcl-1.2.16-x86-64-linux-binary.tar.bz2
# cd sbcl-1.2.16-x86-64-linux
# ./install.sh

# which sbcl
/usr/local/bin/sbcl
# sbcl --version
SBCL 1.2.16

Maximaのインストール

Maximaをインストールする。

# yum install -y texinfo recode

# cd /usr/local/src/
# wget https://downloads.sourceforge.net/project/maxima/Maxima-source/5.36.1-source/maxima-5.36.1.tar.gz
# tar zxf maxima-5.36.1.tar.gz
# cd maxima-5.36.1
# ./configure --enable-sbcl
# make
# make check
# make install

Maximaの動作チェック…OK!

# maxima
Maxima 5.36.1 http://maxima.sourceforge.net
using Lisp SBCL 1.2.16
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) run_testsuite();
(略)
No unexpected errors found out of 10,185 tests.
Evaluation took:
  270.881 seconds of real time
  268.825318 seconds of total run time (265.951735 user, 2.873583 system)
  [ Run times consist of 7.487 seconds GC time, and 261.339 seconds non-GC time. ]
  99.24% CPU
  18,258 forms interpreted
  10,479 lambdas converted
  792,712,305,412 processor cycles
  35,119,738,944 bytes consed

(%o0)                                done

ちなみにSBCL 1.3.18を利用すると動作テストでエラーが出る…
(そのためSBCL 1.2.16をインストールしている)

# maxima
Maxima 5.36.1 http://maxima.sourceforge.net
using Lisp SBCL 1.3.18
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) run_testsuite();
(略)
Error summary:
Errors found in /usr/local/share/maxima/5.36.1/tests/rtest8.mac, problems:
(63 64 66)
Error found in /usr/local/share/maxima/5.36.1/tests/rexamples.mac, problem:
(16)
4 tests failed out of 10,185 total tests.
Evaluation took:
  212.638 seconds of real time
  210.657697 seconds of total run time (208.159435 user, 2.498262 system)
  [ Run times consist of 4.550 seconds GC time, and 206.108 seconds non-GC time. ]
  99.07% CPU
  18,335 forms interpreted
  11,141 lambdas converted
  622,269,303,845 processor cycles
  31,019,882,192 bytes consed

(%o0)                                done

MoodleにSTACKをインストールする

STACK関連モジュール等の追加

# yum install -y gnuplot gnuplot-common
# which gnuplot
/bin/gnuplot

# cd /var/www/html/
# git clone https://github.com/maths/moodle-qbehaviour_dfexplicitvaildate.git question/behaviour/dfexplicitvaildate
# git clone https://github.com/maths/moodle-qbehaviour_dfcbmexplicitvaildate.git question/behaviour/dfcbmexplicitvaildate
# git clone https://github.com/maths/moodle-qbehaviour_adaptivemultipart.git question/behaviour/adaptivemultipart
# git clone https://github.com/maths/moodle-qtype_stack.git question/type/stack

Moodleにインストール

管理者としてMoodleサイトログインして追加されたプラグインをインストール。
STACKの設定として以下の項目を変更して保存する。
CASの結果をキャッシュするとSTACKの実効速度の高速化が期待できるが、後述する高速化設定の効果が大きいことと利用状況によっては数ヶ月でGB単位のキャッシュがDBに記録されてDBから拾ってくる方が遅くなったことがあったため無効にしている。

設定項目 内容
Maximaのバージョン 5.36.1
CASの結果をキャッシュ キャッシュしない
Maximaコマンド timeout --kill-after=10s 10s /usr/local/bin/maxima
gnuplot コマンド /bin/gnuplot

STACK動作テスト+α

[サイト管理] > [プラグイン] > [問題タイプ] > [STACK] を選び、STACKの設定で「動作確認スクリプト」のリンクをクリックする。

SELinuxがEnforcingだとエラーとなるため、以下のコマンドを実行する。

# setenforce 0
# getenforce
Permissive

<ここで動作確認スクリプトを実行>

# grep "sbcl\|timeout\|maxima_opt_auto" /var/log/audit/audit.log | audit2allow --module=maxima -all

module maxima 1.0;

require {
        type httpd_t;
        type ld_so_cache_t;
        class process execmem;
        class file execute;
}

#============= httpd_t ==============
allow httpd_t ld_so_cache_t:file execute;

#!!!! This avc can be allowed using the boolean 'httpd_execmem'
allow httpd_t self:process execmem;

# grep "sbcl\|timeout\|maxima_opt_auto" /var/log/audit/audit.log | audit2allow --module-package=maxima -all
# semodule -i maxima.pp
# setenforce 1
# getenforce
Enforcing

STACKの高速化

そのままでは遅くて使い物にならないので、高速化設定を行う。
設定項目を下記に書き換えて保存した後、前項目と同じようにSELinux対策をする。

設定項目 内容
プラットフォームの種類 Linux(最適化)
Maximaコマンド timeout --kill-after=10s 10s /var/www/moodledata/stack/maxima_opt_auto

高速化設定の効果を確認するため、評価関数の確認スクリプトを実行して処理にかかった時間を比較してみる。

「評価関数の確認スクリプト」実行時間 (単位: 秒)

評価関数 Linux Linux(最適化)
AlgEquiv 543 25

結果としてCASの実効速度が10倍以上に高速化していることがわかる(実際にはMaximaの起動とSTACK用の初期化にかかる時間が短縮されている)。
なお、赤字でテストに失敗した項目がエラーとして表示される場合があるが、英語以外の言語で評価関数のテストをした場合はエラーメッセージが翻訳されているためにアサートに失敗してる可能性があるため、英語に設定して行うこと。
ただしSTACK 3.5.7 (2017060700)のUnitsテストでは2つのテスト項目がエラーとなってしまう

Maximaについての備考

適当なバージョンのMaximaをインストールすると良く分からない不具合が出たりするので推奨されているバージョンを使うのが良いと思う。
https://moodle.org/mod/forum/discuss.php?d=359138

2
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
2
2