{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simname = \"som02_example\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from objsimpy.config import SIMDATA_BASE_DIR, OBJSIM_DIR\n", "import os\n", "\n", "def make_dir_if_needed(dirname):\n", " if not os.path.isdir(dirname):\n", " print(\"--> create directory: {}\".format(dirname))\n", " os.makedirs(dirname)\n", " else:\n", " print(\"directory exists: {}\".format(dirname))\n", "\n", "data_dir = os.path.join(SIMDATA_BASE_DIR, 'objsim', simname)\n", "make_dir_if_needed(data_dir)\n", "\n", "simtime = 1000000." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from objsimpy.runner import ObjsimRunner\n", "n_trials = 4\n", "n_steps = int(simtime//250//n_trials)\n", "default_settings_file = os.path.join(OBJSIM_DIR, 'simulations', 'fm', 'som02', 'settings_som02_gauss.cfg')\n", "\n", "# default settings from .cfg file can be overwritten\n", "changed_settings = ['--NTrials', '4',\n", " '--NSteps', str(n_steps),\n", " #'--TestNSteps', '4',\n", " '--SaveInitialWeights',\n", " '--LearnRate', '0.0002',\n", " '--StimFileName', 'gauss20x20',\n", " ]\n", "\n", "som02_binary = os.path.join(OBJSIM_DIR, 'install', 'bin', 'som02', 'som02')\n", "som02 = ObjsimRunner(som02_binary)\n", "som02.run(data_dir, \n", " default_settings_file, \n", " changed_settings)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "som02.is_running()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fname_output = os.path.join(data_dir, 'output.txt')\n", "def print_last_output_lines(fname, n_lines=3):\n", " with open(fname, 'r') as fobj:\n", " content = fobj.read()\n", " lines = content.split('\\n')\n", " for l in lines[-n_lines:]:\n", " print(l)\n", "print_last_output_lines(fname_output)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import clear_output" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import time\n", "\n", "show_progress_max = 5\n", "count = 0\n", "\n", "while som02.is_running():\n", " count += 1\n", " clear_output()\n", " print(\"count: {}\".format(count))\n", " print_last_output_lines(fname_output)\n", " if count > show_progress_max:\n", " break\n", " time.sleep(4)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "som02.is_running()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ls $data_dir" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.5" } }, "nbformat": 4, "nbformat_minor": 2 }