gamsjupyter01.gms : Test GAMS Jupyter Notebooks

Description

Contributor: Clemens Westphal, September 2020)


Small Model of Type : GAMS


Category : GAMS Test library


Main file : gamsjupyter01.gms

$TITLE 'Test GAMS Jupyter Notebooks' (GAMSJUPYTER01,SEQ=836)

$ontext
Contributor: Clemens Westphal, September 2020)
$offtext

$set srcRoot %gams.sysdir%api%system.dirsep%python%system.dirsep%examples%system.dirsep%magic%system.dirsep%
$set testDir %sysenv.GTESTDIR%%system.dirsep%%sysenv.MODTESTDIR%%system.dirsep%gamsjupyter01

$if not setenv JUPYTER $exit

$onEmbeddedCode Python:
import os
import shutil

def patch_sysdir(file_in, file_out):
    with open(file_in, 'r', encoding='utf-8') as f:
        s = f.read().replace('"%reload_ext gams.magic"', r'"%reload_ext gams.magic\n", "import os\n", "gams.reset(os.environ.get(\"GTESTDIR\", None))"')
    with open(file_out, 'w', encoding='utf-8') as f:
        f.write(s)

test_dir = r"%testDir%"
os.makedirs(test_dir, exist_ok=True)

patch_sysdir(r"%srcRoot%Introduction.ipynb", os.path.join(test_dir, "Introduction.ipynb"))
patch_sysdir(r"%srcRoot%Millco.ipynb", os.path.join(test_dir, "Millco.ipynb"))
patch_sysdir(r"%srcRoot%Polyomino.ipynb", os.path.join(test_dir, "Polyomino.ipynb"))
#patch_sysdir(r"%srcRoot%Pickstock.ipynb", os.path.join(test_dir, "Pickstock.ipynb"))  # #4270
patch_sysdir(r"%srcRoot%NordhausDice.ipynb", os.path.join(test_dir, "NordhausDice.ipynb"))

# copy Pentominos.png required by Polyomino.ipynb
shutil.copy(r"%srcRoot%Pentominos.png", test_dir)

$offEmbeddedCode


$call.checkErrorLevel cd . && "%sysenv.JUPYTER%" nbconvert --to notebook --execute "%testDir%%system.dirsep%Introduction.ipynb" > Introduction.log 2>&1
$call.checkErrorLevel cd . && "%sysenv.JUPYTER%" nbconvert --to notebook --execute "%testDir%%system.dirsep%Millco.ipynb" > Millco.log 2>&1

$if %DEMOSIZE% == 1 $exit

$call.checkErrorLevel cd . && "%sysenv.JUPYTER%" nbconvert --to notebook --execute "%testDir%%system.dirsep%Polyomino.ipynb" > Polyomino.log 2>&1
*$call.checkErrorLevel cd . && "%sysenv.JUPYTER%" nbconvert --to notebook --execute "%testDir%%system.dirsep%Pickstock.ipynb" > Pickstock.log 2>&1 #4270
$call.checkErrorLevel cd . && "%sysenv.JUPYTER%" nbconvert --to notebook --execute "%testDir%%system.dirsep%NordhausDice.ipynb" > NordhausDice.log 2>&1