@@ -50,3 +50,91 @@ you can map your local Weka packages into the container as follows:
5050 docker run --gpus=all -u $( id -u) :$( id -g) \
5151 -v $HOME /wekafiles/:/workspace/wekafiles \
5252 -it fracpete/pww3:0.2.9_cuda10.2
53+
54+
55+ Additional Weka packages
56+ ------------------------
57+
58+ When building Docker images for your environments, your code will most likely rely
59+ on additional Weka packages. You can install the packages by creating a little
60+ Python script that uses python-weka-wrapper3 to install them (just like you would
61+ normally do in a script). Here is the content of the ``install_packages.py ``
62+ script:
63+
64+ .. code-block :: python
65+
66+ import weka.core.jvm as jvm
67+ import weka.core.packages as packages
68+
69+ jvm.start(packages = True )
70+
71+ # for reproducibility, we also specify the version
72+ packages.install_package(" SelfOrganizingMap" , version = " 1.0.3" )
73+
74+ jvm.stop()
75+
76+
77+ A minimal ``Dockerfile `` (in the same directory as ``install_packages.py ``) then looks
78+ like this (using pww3 0.2.9 for CPU):
79+
80+ ::
81+
82+ FROM fracpete/pww3:0.2.9_cpu
83+ COPY install_packages.py /workspace/install_packages.py
84+ RUN python3 /workspace/install_packages.py
85+
86+
87+ You can then build this image just like any other Docker image:
88+
89+ .. code-block :: bash
90+
91+ docker build -t pww3-pkg .
92+
93+
94+ For testing, you can create a local script called ``test_packages.py `` with
95+ the content similar to this:
96+
97+ .. code-block :: python
98+
99+ import weka.core.jvm as jvm
100+ import weka.core.packages as packages
101+ from weka.clusterers import Clusterer
102+
103+ jvm.start(packages = True )
104+
105+ # list packages
106+ items = packages.installed_packages()
107+ for item in items:
108+ print (item.name + " /" + item.version + " \n " + item.url)
109+
110+ # instantiate from package
111+ cls = Clusterer(classname = " weka.clusterers.SelfOrganizingMap" )
112+ print (cls .to_commandline())
113+
114+ jvm.stop()
115+
116+
117+ The following command simply runs our ``test_packages.py `` script. To achieve this,
118+ the command maps the current directory (``pwd ``) into the container's ``/workspace/scripts ``
119+ directory:
120+
121+ .. code-block :: bash
122+
123+ docker run \
124+ -v ` pwd` :/workspace/scripts \
125+ -t pww3-pkg:latest \
126+ python3 /workspace/scripts/test_packages.py
127+
128+
129+ The output will be something like this:
130+
131+ ::
132+
133+ DEBUG:weka.core.jvm:Adding bundled jars
134+ DEBUG:weka.core.jvm:Classpath=['/usr/local/lib/python3.8/dist-packages/javabridge/jars/rhino-1.7R4.jar', '/usr/local/lib/python3.8/dist-packages/javabridge/jars/runnablequeue.jar', '/usr/local/lib/python3.8/dist-packages/javabridge/jars/cpython.jar', '/usr/local/lib/python3.8/dist-packages/weka/lib/weka.jar', '/usr/local/lib/python3.8/dist-packages/weka/lib/python-weka-wrapper.jar']
135+ DEBUG:weka.core.jvm:MaxHeapSize=default
136+ DEBUG:weka.core.jvm:Package support enabled
137+ SelfOrganizingMap/1.0.3
138+ http://prdownloads.sourceforge.net/wekann/SelfOrganizingMap1.0.3.zip?download
139+ weka.clusterers.SelfOrganizingMap -L 1.0 -O 2000 -C 1000 -H 2 -W 2
140+
0 commit comments