diff --git a/maestroflame/examples/Julia_plotting.ipynb b/maestroflame/examples/Julia_plotting.ipynb new file mode 100644 index 0000000..d79f6bd --- /dev/null +++ b/maestroflame/examples/Julia_plotting.ipynb @@ -0,0 +1,294 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook attempts to speed up the prediction_vs_solution plot with julia.\n", + "There are 3 julia methods.\n", + "\n", + "1. Is loading julia from a system image and calling julia from python. You will need to run the `tools/make_sysimage.jl` file. This will take a while to run. After, try running the `tools/test_sysimage.py` file. This will make sure everything is working properly for maestroflame to run julia. \n", + "\n", + "2. Takes a more naive approach, outputting files to disk and then using `os.system()` commands to call a julia script `maestroflame/pred_v_sol.jl`. This is slow because of the start up time. \n", + "\n", + "3. A third incomplete method that I had trouble getting to work was loading julia fron a virtual enviroment. Within the `pred_v_sol.jl` file you can see the load env commands. This might get around the julia start up time?\n", + "\n", + "## Results:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Processing /Users/chris/Desktop/temp/ml-reactions/maestroflame\n", + "Requirement already satisfied: matplotlib==3.4.1 in /Users/chris/anaconda3/lib/python3.8/site-packages (from MaestroFlame==0.1.0) (3.4.1)\n", + "Requirement already satisfied: optuna==2.8.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from MaestroFlame==0.1.0) (2.8.0)\n", + "Requirement already satisfied: pandas==1.1.3 in /Users/chris/anaconda3/lib/python3.8/site-packages (from MaestroFlame==0.1.0) (1.1.3)\n", + "Requirement already satisfied: numpy==1.21.1 in /Users/chris/anaconda3/lib/python3.8/site-packages (from MaestroFlame==0.1.0) (1.21.1)\n", + "Requirement already satisfied: yt==4.0.1 in /Users/chris/anaconda3/lib/python3.8/site-packages (from MaestroFlame==0.1.0) (4.0.1)\n", + "Requirement already satisfied: torch==1.9.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from MaestroFlame==0.1.0) (1.9.0)\n", + "Requirement already satisfied: ipython==7.27.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from MaestroFlame==0.1.0) (7.27.0)\n", + "Requirement already satisfied: pillow>=6.2.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from matplotlib==3.4.1->MaestroFlame==0.1.0) (8.3.1)\n", + "Requirement already satisfied: pyparsing>=2.2.1 in /Users/chris/anaconda3/lib/python3.8/site-packages (from matplotlib==3.4.1->MaestroFlame==0.1.0) (2.4.7)\n", + "Requirement already satisfied: kiwisolver>=1.0.1 in /Users/chris/anaconda3/lib/python3.8/site-packages (from matplotlib==3.4.1->MaestroFlame==0.1.0) (1.3.1)\n", + "Requirement already satisfied: cycler>=0.10 in /Users/chris/anaconda3/lib/python3.8/site-packages (from matplotlib==3.4.1->MaestroFlame==0.1.0) (0.10.0)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /Users/chris/anaconda3/lib/python3.8/site-packages (from matplotlib==3.4.1->MaestroFlame==0.1.0) (2.8.2)\n", + "Requirement already satisfied: tqdm in /Users/chris/anaconda3/lib/python3.8/site-packages (from optuna==2.8.0->MaestroFlame==0.1.0) (4.50.2)\n", + "Requirement already satisfied: sqlalchemy>=1.1.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from optuna==2.8.0->MaestroFlame==0.1.0) (1.3.20)\n", + "Requirement already satisfied: cmaes>=0.8.2 in /Users/chris/anaconda3/lib/python3.8/site-packages (from optuna==2.8.0->MaestroFlame==0.1.0) (0.8.2)\n", + "Requirement already satisfied: packaging>=20.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from optuna==2.8.0->MaestroFlame==0.1.0) (21.0)\n", + "Requirement already satisfied: cliff in /Users/chris/anaconda3/lib/python3.8/site-packages (from optuna==2.8.0->MaestroFlame==0.1.0) (3.8.0)\n", + "Requirement already satisfied: alembic in /Users/chris/anaconda3/lib/python3.8/site-packages (from optuna==2.8.0->MaestroFlame==0.1.0) (1.6.5)\n", + "Requirement already satisfied: scipy!=1.4.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from optuna==2.8.0->MaestroFlame==0.1.0) (1.5.2)\n", + "Requirement already satisfied: colorlog in /Users/chris/anaconda3/lib/python3.8/site-packages (from optuna==2.8.0->MaestroFlame==0.1.0) (5.0.1)\n", + "Requirement already satisfied: pytz>=2017.2 in /Users/chris/anaconda3/lib/python3.8/site-packages (from pandas==1.1.3->MaestroFlame==0.1.0) (2019.3)\n", + "Requirement already satisfied: setuptools>=19.6 in /Users/chris/anaconda3/lib/python3.8/site-packages (from yt==4.0.1->MaestroFlame==0.1.0) (57.4.0)\n", + "Requirement already satisfied: toml>=0.10.2 in /Users/chris/anaconda3/lib/python3.8/site-packages (from yt==4.0.1->MaestroFlame==0.1.0) (0.10.2)\n", + "Requirement already satisfied: pyyaml>=4.2b1 in /Users/chris/anaconda3/lib/python3.8/site-packages (from yt==4.0.1->MaestroFlame==0.1.0) (5.3.1)\n", + "Requirement already satisfied: more-itertools>=8.4 in /Users/chris/anaconda3/lib/python3.8/site-packages (from yt==4.0.1->MaestroFlame==0.1.0) (8.6.0)\n", + "Requirement already satisfied: sympy>=1.2 in /Users/chris/anaconda3/lib/python3.8/site-packages (from yt==4.0.1->MaestroFlame==0.1.0) (1.6.2)\n", + "Requirement already satisfied: unyt>=2.8.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from yt==4.0.1->MaestroFlame==0.1.0) (2.8.0)\n", + "Requirement already satisfied: typing-extensions in /Users/chris/anaconda3/lib/python3.8/site-packages (from torch==1.9.0->MaestroFlame==0.1.0) (3.7.4.3)\n", + "Requirement already satisfied: decorator in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (5.0.9)\n", + "Requirement already satisfied: jedi>=0.16 in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (0.18.0)\n", + "Requirement already satisfied: traitlets>=4.2 in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (5.0.5)\n", + "Requirement already satisfied: backcall in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (0.2.0)\n", + "Requirement already satisfied: pexpect>4.3; sys_platform != \"win32\" in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (4.8.0)\n", + "Requirement already satisfied: pickleshare in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (0.7.5)\n", + "Requirement already satisfied: matplotlib-inline in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (0.1.3)\n", + "Requirement already satisfied: pygments in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (2.7.2)\n", + "Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (3.0.19)\n", + "Requirement already satisfied: appnope; sys_platform == \"darwin\" in /Users/chris/anaconda3/lib/python3.8/site-packages (from ipython==7.27.0->MaestroFlame==0.1.0) (0.1.0)\n", + "Requirement already satisfied: six in /Users/chris/anaconda3/lib/python3.8/site-packages (from cycler>=0.10->matplotlib==3.4.1->MaestroFlame==0.1.0) (1.16.0)\n", + "Requirement already satisfied: PrettyTable>=0.7.2 in /Users/chris/anaconda3/lib/python3.8/site-packages (from cliff->optuna==2.8.0->MaestroFlame==0.1.0) (2.1.0)\n", + "Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from cliff->optuna==2.8.0->MaestroFlame==0.1.0) (5.6.0)\n", + "Requirement already satisfied: cmd2>=1.0.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from cliff->optuna==2.8.0->MaestroFlame==0.1.0) (2.1.1)\n", + "Requirement already satisfied: stevedore>=2.0.1 in /Users/chris/anaconda3/lib/python3.8/site-packages (from cliff->optuna==2.8.0->MaestroFlame==0.1.0) (3.3.0)\n", + "Requirement already satisfied: Mako in /Users/chris/anaconda3/lib/python3.8/site-packages (from alembic->optuna==2.8.0->MaestroFlame==0.1.0) (1.1.4)\n", + "Requirement already satisfied: python-editor>=0.3 in /Users/chris/anaconda3/lib/python3.8/site-packages (from alembic->optuna==2.8.0->MaestroFlame==0.1.0) (1.0.4)\n", + "Requirement already satisfied: mpmath>=0.19 in /Users/chris/anaconda3/lib/python3.8/site-packages (from sympy>=1.2->yt==4.0.1->MaestroFlame==0.1.0) (1.1.0)\n", + "Requirement already satisfied: parso<0.9.0,>=0.8.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from jedi>=0.16->ipython==7.27.0->MaestroFlame==0.1.0) (0.8.2)\n", + "Requirement already satisfied: ipython-genutils in /Users/chris/anaconda3/lib/python3.8/site-packages (from traitlets>=4.2->ipython==7.27.0->MaestroFlame==0.1.0) (0.2.0)\n", + "Requirement already satisfied: ptyprocess>=0.5 in /Users/chris/anaconda3/lib/python3.8/site-packages (from pexpect>4.3; sys_platform != \"win32\"->ipython==7.27.0->MaestroFlame==0.1.0) (0.6.0)\n", + "Requirement already satisfied: wcwidth in /Users/chris/anaconda3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython==7.27.0->MaestroFlame==0.1.0) (0.2.5)\n", + "Requirement already satisfied: pyperclip>=1.6 in /Users/chris/anaconda3/lib/python3.8/site-packages (from cmd2>=1.0.0->cliff->optuna==2.8.0->MaestroFlame==0.1.0) (1.8.2)\n", + "Requirement already satisfied: attrs>=16.3.0 in /Users/chris/anaconda3/lib/python3.8/site-packages (from cmd2>=1.0.0->cliff->optuna==2.8.0->MaestroFlame==0.1.0) (20.3.0)\n", + "Requirement already satisfied: colorama>=0.3.7 in /Users/chris/anaconda3/lib/python3.8/site-packages (from cmd2>=1.0.0->cliff->optuna==2.8.0->MaestroFlame==0.1.0) (0.4.4)\n", + "Requirement already satisfied: MarkupSafe>=0.9.2 in /Users/chris/anaconda3/lib/python3.8/site-packages (from Mako->alembic->optuna==2.8.0->MaestroFlame==0.1.0) (1.1.1)\n", + "Building wheels for collected packages: MaestroFlame\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Building wheel for MaestroFlame (setup.py) ... \u001b[?25ldone\n", + "\u001b[?25h Created wheel for MaestroFlame: filename=MaestroFlame-0.1.0-py3-none-any.whl size=28531 sha256=0a411bbb250fe1e3761e58587637eedb752d622392253476ddbf476399689040\n", + " Stored in directory: /private/var/folders/j8/2s1d11vs6xx9g1f18gn0y4rm0000gn/T/pip-ephem-wheel-cache-0r7mzeag/wheels/bc/1a/ae/3d3ed493ea0c7ad32bf5ff3d67158953fe0de6520f90944766\n", + "Successfully built MaestroFlame\n", + "Installing collected packages: MaestroFlame\n", + " Attempting uninstall: MaestroFlame\n", + " Found existing installation: MaestroFlame 0.1.0\n", + " Uninstalling MaestroFlame-0.1.0:\n", + " Successfully uninstalled MaestroFlame-0.1.0\n", + "Successfully installed MaestroFlame-0.1.0\n" + ] + } + ], + "source": [ + "!pip install ../" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import maestroflame" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "#this is the path to your data files\n", + "data_path = '../../data/data1/flame/'\n", + "\n", + "#These is the input/output prefix of your datafile names.\n", + "input_prefix = 'react_inputs_*'\n", + "output_prefix = 'react_outputs_*'\n", + "\n", + "#Plotfile prefixes, used for visualization purposes.\n", + "plotfile_prefix = 'flame_*'\n", + "\n", + "#By default, this package will save your model, logs of the training and testing data during training,\n", + "#and plots to a directory. Here you specify that directory.\n", + "output_dir = '/Users/chris/Desktop/temp/ml-reactions/maestroflame/examples/testing123/'\n", + "\n", + "#The log file. Everything that is printed during training also goes into this file in case something\n", + "#gets interrupted.\n", + "log_file = output_dir + \"log.txt\"" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "#We first remove the directory we just generated. If you don't do this you'll get an error. This is to protect\n", + "#this package from overwriting your data in case one forgets to change the output_dir when training a new model\n", + "\n", + "!rm -r testing123/" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Model starting on : 12/16/2021 14:03:57\n", + "input_prefix react_inputs_*\n", + "output_prefix react_outputs_*\n", + "output_dir /Users/chris/Desktop/temp/ml-reactions/maestroflame/examples/testing123/\n", + "DEBUG_MODE True\n", + "DO_PLOTTING True\n", + "DO_HYPER_OPTIMIZATION False\n", + "Loading Input Files...\n", + "Loading Output Files...\n", + "Loaded data successfully!\n" + ] + } + ], + "source": [ + "from maestroflame.train import NuclearReactionML\n", + "nrml = NuclearReactionML(data_path, input_prefix, output_prefix, plotfile_prefix,\n", + " output_dir, log_file, DEBUG_MODE=True, DO_PLOTTING=True,\n", + " SAVE_MODEL=True, DO_HYPER_OPTIMIZATION=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cost at epoch 0 is 32.22436998435723\n", + "Saving...\n" + ] + } + ], + "source": [ + "#the package provides preset up loss functions and networks to use\n", + "from maestroflame.losses import log_loss\n", + "from maestroflame.networks import Net\n", + "import torch.optim as optim\n", + "import torch\n", + "\n", + "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", + "\n", + "num_epochs = 1\n", + "model = Net(16, 16, 16, 16, 14)\n", + "\n", + "# get model to cuda if possible\n", + "model.to(device=device)\n", + "optimizer = optim.Adam(model.parameters(), lr=1e-5)\n", + "\n", + "nrml.train(model, optimizer, num_epochs, log_loss, save_every_N=10)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "--- Internal Timing Julia\n", + "8.286669969558716 seconds to start julia \n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/chris/anaconda3/lib/python3.8/site-packages/maestroflame/plotting.py:115: RuntimeWarning: invalid value encountered in log10\n", + " pred_plot = np.log10(pred_plot)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "29.997073888778687 seconds to do preprocessing \n", + "10.120919942855835 seconds to do plot \n", + "48.40560579299927 seconds total for first julia plotting method \n", + "0.33952999114990234 seconds to save data to file \n", + "46.47067403793335 seconds to run julia pred_v_sol.jl \n", + "46.81110095977783 seconds total to run julia method 2 \n", + "6.319821119308472 seconds total for python \n" + ] + } + ], + "source": [ + "from maestroflame.plotting import plotting_standard\n", + "\n", + "import time\n", + "\n", + "plot_class = plotting_standard(nrml.model, nrml.fields, nrml.test_loader, nrml.cost_per_epoc, nrml.component_losses_test,\n", + " nrml.component_losses_train, nrml.cost_per_epoc_test, nrml.output_dir)\n", + "\n", + "plot_class.do_prediction_vs_solution_plot(use_julia=True)\n", + "\n", + "start_time = time.time()\n", + "plot_class.do_prediction_vs_solution_plot(use_julia=False)\n", + "print(\"%s seconds total for python \" % (time.time() - start_time))" + ] + }, + { + "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.8.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/maestroflame/maestroflame/julia_env/Manifest.toml b/maestroflame/maestroflame/julia_env/Manifest.toml new file mode 100644 index 0000000..50bd252 --- /dev/null +++ b/maestroflame/maestroflame/julia_env/Manifest.toml @@ -0,0 +1,525 @@ +# This file is machine-generated - editing it directly is not advised + +[[Adapt]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "84918055d15b3114ede17ac6a7182f68870c16f7" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "3.3.1" + +[[Artifacts]] +deps = ["Pkg"] +git-tree-sha1 = "c30985d8821e0cd73870b17b0ed0ce6dc44cb744" +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" +version = "1.3.0" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[Bzip2_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "c3598e525718abcc440f69cc6d5f60dda0a1b61e" +uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" +version = "1.0.6+5" + +[[ChainRulesCore]] +deps = ["Compat", "LinearAlgebra", "SparseArrays"] +git-tree-sha1 = "f885e7e7c124f8c92650d61b9477b9ac2ee607dd" +uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +version = "1.11.1" + +[[ChangesOfVariables]] +deps = ["LinearAlgebra", "Test"] +git-tree-sha1 = "9a1d594397670492219635b35a3d830b04730d62" +uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0" +version = "0.1.1" + +[[ColorSchemes]] +deps = ["ColorTypes", "Colors", "FixedPointNumbers", "Random"] +git-tree-sha1 = "a851fec56cb73cfdf43762999ec72eff5b86882a" +uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4" +version = "3.15.0" + +[[ColorTypes]] +deps = ["FixedPointNumbers", "Random"] +git-tree-sha1 = "32a2b8af383f11cbb65803883837a149d10dfe8a" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.10.12" + +[[Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "Reexport"] +git-tree-sha1 = "417b0ed7b8b838aa6ca0a87aadf1bb9eb111ce40" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.12.8" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "dce3e3fea680869eaa0b774b2e8343e9ff442313" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "3.40.0" + +[[Conda]] +deps = ["JSON", "VersionParsing"] +git-tree-sha1 = "299304989a5e6473d985212c28928899c74e9421" +uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d" +version = "1.5.2" + +[[Contour]] +deps = ["StaticArrays"] +git-tree-sha1 = "9f02045d934dc030edad45944ea80dbd1f0ebea7" +uuid = "d38c429a-6771-53c6-b99e-75d170b6e991" +version = "0.5.7" + +[[DataAPI]] +git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.9.0" + +[[DataStructures]] +deps = ["Compat", "InteractiveUtils", "OrderedCollections"] +git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.18.10" + +[[DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[DocStringExtensions]] +deps = ["LibGit2"] +git-tree-sha1 = "b19534d1895d702889b219c382a6e18010797f0b" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.8.6" + +[[EarCut_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "92d8f9f208637e8d2d28c664051a00569c01493d" +uuid = "5ae413db-bbd1-5e63-b57d-d24a61df00f5" +version = "2.1.5+1" + +[[FFMPEG]] +deps = ["FFMPEG_jll"] +git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8" +uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a" +version = "0.4.1" + +[[FFMPEG_jll]] +deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "LibVPX_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "Pkg", "Zlib_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"] +git-tree-sha1 = "3cc57ad0a213808473eafef4845a74766242e05f" +uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5" +version = "4.3.1+4" + +[[FixedPointNumbers]] +deps = ["Statistics"] +git-tree-sha1 = "335bfdceacc84c5cdf16aadc768aa5ddfc5383cc" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.8.4" + +[[Formatting]] +deps = ["Printf"] +git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8" +uuid = "59287772-0a20-5a39-b81b-1366585eb4c0" +version = "0.4.2" + +[[FreeType2_jll]] +deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] +git-tree-sha1 = "cbd58c9deb1d304f5a245a0b7eb841a2560cfec6" +uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7" +version = "2.10.1+5" + +[[FriBidi_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "0d20aed5b14dd4c9a2453c1b601d08e1149679cc" +uuid = "559328eb-81f9-559d-9380-de523a88c83c" +version = "1.0.5+6" + +[[GR]] +deps = ["Base64", "DelimitedFiles", "HTTP", "JSON", "LinearAlgebra", "Printf", "Random", "Serialization", "Sockets", "Test", "UUIDs"] +git-tree-sha1 = "cd0f34bd097d4d5eb6bbe01778cf8a7ed35f29d9" +uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" +version = "0.52.0" + +[[GeometryBasics]] +deps = ["EarCut_jll", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"] +git-tree-sha1 = "15ff9a14b9e1218958d3530cc288cf31465d9ae2" +uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326" +version = "0.3.13" + +[[GeometryTypes]] +deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "StaticArrays"] +git-tree-sha1 = "07194161fe4e181c6bf51ef2e329ec4e7d050fc4" +uuid = "4d00f742-c7ba-57c2-abde-4428a4b178cb" +version = "0.8.4" + +[[Grisu]] +git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2" +uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe" +version = "1.0.2" + +[[HTTP]] +deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"] +git-tree-sha1 = "c7ec02c4c6a039a98a15f955462cd7aea5df4508" +uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" +version = "0.8.19" + +[[IniFile]] +deps = ["Test"] +git-tree-sha1 = "098e4d2c533924c921f9f9847274f2ad89e018b8" +uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f" +version = "0.5.0" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[InverseFunctions]] +deps = ["Test"] +git-tree-sha1 = "a7254c0acd8e62f1ac75ad24d5db43f5f19f3c65" +uuid = "3587e190-3f89-42d0-90ee-14403ec27112" +version = "0.1.2" + +[[IrrationalConstants]] +git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151" +uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" +version = "0.1.1" + +[[IterTools]] +git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18" +uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" +version = "1.3.0" + +[[IteratorInterfaceExtensions]] +git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" +uuid = "82899510-4779-5014-852e-03e436cf321d" +version = "1.0.0" + +[[JLLWrappers]] +deps = ["Preferences"] +git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e" +uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" +version = "1.3.0" + +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "8076680b162ada2a031f707ac7b4953e30667a37" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.2" + +[[LAME_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "df381151e871f41ee86cee4f5f6fd598b8a68826" +uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d" +version = "3.100.0+3" + +[[LaTeXStrings]] +git-tree-sha1 = "f2355693d6778a178ade15952b7ac47a4ff97996" +uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +version = "1.3.0" + +[[Latexify]] +deps = ["Formatting", "InteractiveUtils", "LaTeXStrings", "MacroTools", "Markdown", "Printf", "Requires"] +git-tree-sha1 = "7c72983c6daf61393ee8a0b29a419c709a06cede" +uuid = "23fbe1c1-3f47-55db-b15f-69d7ec21a316" +version = "0.14.12" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[LibVPX_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "85fcc80c3052be96619affa2fe2e6d2da3908e11" +uuid = "dd192d2f-8180-539f-9fb4-cc70b1dcf69a" +version = "1.9.0+1" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[LogExpFunctions]] +deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"] +git-tree-sha1 = "be9eef9f9d78cecb6f262f3c10da151a6c5ab827" +uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" +version = "0.3.5" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[MacroTools]] +deps = ["Markdown", "Random"] +git-tree-sha1 = "3d3e902b31198a27340d0bf00d6ac452866021cf" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.5.9" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[MbedTLS]] +deps = ["Dates", "MbedTLS_jll", "Random", "Sockets"] +git-tree-sha1 = "1c38e51c3d08ef2278062ebceade0e46cefc96fe" +uuid = "739be429-bea8-5141-9913-cc70e7f3736d" +version = "1.0.3" + +[[MbedTLS_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "0eef589dd1c26a3ac9d753fe1a8bcad63f956fa6" +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.16.8+1" + +[[Measures]] +git-tree-sha1 = "e498ddeee6f9fdb4551ce855a46f54dbd900245f" +uuid = "442fdcdd-2543-5da2-b0f3-8c86c306513e" +version = "0.3.1" + +[[Missings]] +deps = ["DataAPI"] +git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "1.0.2" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[NaNMath]] +git-tree-sha1 = "bfe47e760d60b82b66b61d2d44128b62e3a369fb" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "0.3.5" + +[[Ogg_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "a42c0f138b9ebe8b58eba2271c5053773bde52d0" +uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051" +version = "1.3.4+2" + +[[OpenSSL_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "71bbbc616a1d710879f5a1021bcba65ffba6ce58" +uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" +version = "1.1.1+6" + +[[Opus_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "f9d57f4126c39565e05a2b0264df99f497fc6f37" +uuid = "91d4177d-7536-5919-b921-800302f37372" +version = "1.3.1+3" + +[[OrderedCollections]] +git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.4.1" + +[[Parsers]] +deps = ["Dates"] +git-tree-sha1 = "ae4bbcadb2906ccc085cf52ac286dc1377dceccc" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.1.2" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Test", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[PlotThemes]] +deps = ["PlotUtils", "Requires", "Statistics"] +git-tree-sha1 = "a3a964ce9dc7898193536002a6dd892b1b5a6f1d" +uuid = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a" +version = "2.0.1" + +[[PlotUtils]] +deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"] +git-tree-sha1 = "b084324b4af5a438cd63619fd006614b3b20b87b" +uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043" +version = "1.0.15" + +[[Plots]] +deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "GeometryTypes", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "Pkg", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"] +git-tree-sha1 = "f4425bbd5f313b074d6ce3b86d80c0ad16bf7326" +uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +version = "1.6.12" + +[[Preferences]] +deps = ["TOML"] +git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a" +uuid = "21216c6a-2e73-6563-6e65-726566657250" +version = "1.2.2" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[PyCall]] +deps = ["Conda", "Dates", "Libdl", "LinearAlgebra", "MacroTools", "Serialization", "VersionParsing"] +git-tree-sha1 = "4ba3651d33ef76e24fef6a598b63ffd1c5e1cd17" +uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" +version = "1.92.5" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[RecipesBase]] +git-tree-sha1 = "44a75aa7a527910ee3d1751d1f0e4148698add9e" +uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" +version = "1.1.2" + +[[RecipesPipeline]] +deps = ["Dates", "NaNMath", "PlotUtils", "RecipesBase"] +git-tree-sha1 = "4a325c9bcc2d8e62a8f975b9666d0251d53b63b9" +uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c" +version = "0.1.13" + +[[Reexport]] +deps = ["Pkg"] +git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "0.2.0" + +[[Requires]] +deps = ["UUIDs"] +git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621" +uuid = "ae029012-a4dd-5104-9daa-d747884805df" +version = "1.1.3" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Showoff]] +deps = ["Dates", "Grisu"] +git-tree-sha1 = "ee010d8f103468309b8afac4abb9be2e18ff1182" +uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" +version = "0.3.2" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SortingAlgorithms]] +deps = ["DataStructures"] +git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "1.0.1" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[StaticArrays]] +deps = ["LinearAlgebra", "Random", "Statistics"] +git-tree-sha1 = "3c76dde64d03699e074ac02eb2e8ba8254d428da" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "1.2.13" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[StatsAPI]] +git-tree-sha1 = "0f2aa8e32d511f758a2ce49208181f7733a0936a" +uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0" +version = "1.1.0" + +[[StatsBase]] +deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"] +git-tree-sha1 = "2bb0cb32026a66037360606510fca5984ccc6b75" +uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +version = "0.33.13" + +[[StructArrays]] +deps = ["Adapt", "DataAPI", "StaticArrays", "Tables"] +git-tree-sha1 = "2ce41e0d042c60ecd131e9fb7154a3bfadbf50d3" +uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" +version = "0.6.3" + +[[TOML]] +deps = ["Dates"] +git-tree-sha1 = "44aaac2d2aec4a850302f9aa69127c74f0c3787e" +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.3" + +[[TableTraits]] +deps = ["IteratorInterfaceExtensions"] +git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39" +uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +version = "1.0.1" + +[[Tables]] +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] +git-tree-sha1 = "fed34d0e71b91734bf0a7e10eb1bb05296ddbcd0" +uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +version = "1.6.0" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[VersionParsing]] +git-tree-sha1 = "e575cf85535c7c3292b4d89d89cc29e8c3098e47" +uuid = "81def892-9a0e-5fdd-b105-ffc91e053289" +version = "1.2.1" + +[[Zlib_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "320228915c8debb12cb434c59057290f0834dbf6" +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.11+18" + +[[libass_jll]] +deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll"] +git-tree-sha1 = "acc685bcf777b2202a904cdcb49ad34c2fa1880c" +uuid = "0ac62f75-1d6f-5e53-bd7c-93b484bb37c0" +version = "0.14.0+4" + +[[libfdk_aac_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "7a5780a0d9c6864184b3a2eeeb833a0c871f00ab" +uuid = "f638f0a6-7fb0-5443-88ba-1cc74229b280" +version = "0.1.6+4" + +[[libvorbis_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"] +git-tree-sha1 = "fa14ac25af7a4b8a7f61b287a124df7aab601bcd" +uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a" +version = "1.3.6+6" + +[[x264_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "d713c1ce4deac133e3334ee12f4adff07f81778f" +uuid = "1270edf5-f2f9-52d2-97e9-ab00b5d0237a" +version = "2020.7.14+2" + +[[x265_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "487da2f8f2f0c8ee0e83f39d13037d6bbf0a45ab" +uuid = "dfaa095f-4041-5dcd-9319-2fabd8486b76" +version = "3.0.0+3" diff --git a/maestroflame/maestroflame/julia_env/Project.toml b/maestroflame/maestroflame/julia_env/Project.toml new file mode 100644 index 0000000..92cd2ae --- /dev/null +++ b/maestroflame/maestroflame/julia_env/Project.toml @@ -0,0 +1,3 @@ +[deps] +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" diff --git a/maestroflame/maestroflame/plotting.py b/maestroflame/maestroflame/plotting.py index 53a2665..c957037 100644 --- a/maestroflame/maestroflame/plotting.py +++ b/maestroflame/maestroflame/plotting.py @@ -4,6 +4,10 @@ import matplotlib import torch import os +import sys +import julia +import time +from numpy import errstate,isneginf, isposinf def make_movie(file_list, save_dir='./', var='enuc', movie_name="flame.mp4"): i = 1 @@ -16,7 +20,6 @@ def make_movie(file_list, save_dir='./', var='enuc', movie_name="flame.mp4"): os.system("rm movie_imag*") Video("movie.mp4", embed=True) - class plotting_standard: #class to make it easy to plot things from driver. Set up all the data #then just call the methods for whatever plots you want. @@ -41,10 +44,9 @@ def __init__(self, model, fields, test_loader, cost_per_epoc, os.mkdir(output_dir) - def do_prediction_vs_solution_plot(self): + def do_prediction_vs_solution_plot(self, use_julia=False): ############ Prediction Vs Solution Plot Should fall one y=x line. - plt.figure() #N = react_data.output_data.shape[1] colors = matplotlib.cm.rainbow(np.linspace(0, 1, self.nnuc+1)) @@ -66,41 +68,105 @@ def do_prediction_vs_solution_plot(self): #for batch_idx, (data, targets) in enumerate(self.test_loader): pred = self.model(data_whole) - #print(pred.shape) - for i in range(pred.shape[0]): - if i == 0: - for j in range(pred.shape[1]): - plt.scatter(pred[i,j], targets_whole[i,j], color=colors[j], label=self.fields[j]) - else: - plt.scatter(pred[i, :], targets_whole[i, :self.nnuc+1], c=colors) + + + if use_julia: + + outer_start_time = time.time() + start_time = time.time() + + + # if self.output_dir[0] != '/': + # print("You must supply output_dir as an absolute path if you are going to \ + # to use julia plotting!") + # sys.exit() + # + dir_path = os.path.dirname(os.path.realpath(__file__)) #+ '/maestroflame/' + + + np.savetxt(self.output_dir + '/targets.txt', targets_whole) + np.savetxt(self.output_dir + '/pred.txt', pred) + #np.savetxt(self.output_dir + '/labels.txt', self.fields + [self.output_dir, dir_path], fmt="%s") + + from julia.api import LibJulia + api = LibJulia.load() + #api.sysimage = "sys_plots.so" + api.sysimage = "../tools/sys.so" + api.init_julia() + from julia import Plots + + print("--- Internal Timing Julia") + print("%s seconds to start julia " % (time.time() - start_time)) + start_time = time.time() + + #TODO: can't get labels to work. + #Plots.scatter(pred, targets_whole, labels=self.fields, dpi=600) + + pred_plot = pred.cpu().detach().numpy() + targets_plot = targets_whole.cpu().detach().numpy() + + Plots.scatter(pred_plot, targets_plot, dpi=600, xlabel='Prediction', ylabel='Solution') + Plots.savefig(self.output_dir + "julia_prediction_vs_solution.png") + + #screen out zeros when taking log. Julia log plots can't handle zeros + #so we just do it for them. + + with errstate(divide='ignore'): + pred_plot = np.log10(pred_plot) + targets_plot = np.log10(targets_plot) + + #screen + pred_plot_sc = pred_plot + targets_plot_sc = targets_plot + + mask = np.isinf(pred_plot) + np.isinf(targets_plot) + np.isnan(pred_plot) + np.isnan(targets_plot) + + pred_plot_sc[mask]=0. + targets_plot_sc[mask]=0. + print("%s seconds to do preprocessing " % (time.time() - start_time)) + start_time = time.time() + + Plots.scatter(pred_plot, targets_plot, dpi=600, xlabel='log10(Prediction)', ylabel='log10(Solution)') + Plots.savefig(self.output_dir + "julia_prediction_vs_solution_log.png") + print("%s seconds to do plot " % (time.time() - start_time)) + print("%s seconds total for first julia plotting method " % (time.time() - outer_start_time)) + + + outer_start_time = time.time() + start_time = time.time() + + if not os.path.isdir(dir_path + "/python_to_julia_data"): + os.mkdir(dir_path + "/python_to_julia_data") + np.savetxt(dir_path + "/python_to_julia_data/"+"pred.txt", pred) + np.savetxt(dir_path + "/python_to_julia_data/"+"targets.txt", targets_whole) + str_to_julia = self.fields + [self.output_dir] + + np.savetxt(dir_path + "/python_to_julia_data/"+"labels.txt", str_to_julia, fmt="%s") + print("%s seconds to save data to file " % (time.time() - start_time)) + start_time = time.time() + + + os.system(f"julia {dir_path}"+"/pred_v_sol.jl") + print("%s seconds to run julia pred_v_sol.jl " % (time.time() - start_time)) + print("%s seconds total to run julia method 2 " % (time.time() - outer_start_time)) + + else: + for i in range(pred.shape[1]): + plt.scatter(pred[:, i], targets_whole[:, i], color=colors[i], label=self.fields[i]) + plt.plot(np.linspace(0, 1), np.linspace(0,1), '--', color='orange') + #plt.legend(yt.load(react_data.output_files[0]).field_list, colors=colors) + plt.legend(bbox_to_anchor=(1, 1)) + plt.xlabel('Prediction') + plt.ylabel('Solution') + plt.savefig(self.output_dir + "/prediction_vs_solution.png", bbox_inches='tight') + + plt.yscale("log") + plt.xscale("log") + plt.savefig(self.output_dir + "/prediction_vs_solution_log.png", bbox_inches='tight') self.model.train() - # plt.figure() - # #N = react_data.output_data.shape[1] - # colors = matplotlib.cm.rainbow(np.linspace(0, 1, self.N_fields)) - # #fields = [field[1] for field in yt.load(react_data.output_files[0]).field_list] - # with torch.no_grad(): - # losses = [] - # for batch_idx, (data, targets) in enumerate(self.test_loader): - # pred = self.model(data) - # for i in range(pred.shape[0]): - # if i == 0 and batch_idx == 0: - # for j in range(pred.shape[1]): - # plt.scatter(pred[i,j], targets[i,j], color=colors[j], label=self.fields[j]) - # else: - # plt.scatter(pred[i, :], targets[i, :], c=colors) - # # if batch_idx == 100: - # # break - plt.plot(np.linspace(0, 1), np.linspace(0,1), '--', color='orange') - #plt.legend(yt.load(react_data.output_files[0]).field_list, colors=colors) - plt.legend(bbox_to_anchor=(1, 1)) - plt.xlabel('Prediction') - plt.ylabel('Solution') - plt.savefig(self.output_dir + "/prediction_vs_solution.png", bbox_inches='tight') - plt.yscale("log") - plt.xscale("log") - plt.savefig(self.output_dir + "/prediction_vs_solution_log.png", bbox_inches='tight') + def do_cost_per_epoch_plot(self): @@ -223,7 +289,7 @@ def do_prediction_vs_solution_plot(self): colors = matplotlib.cm.rainbow(np.linspace(0, 1, self.nnuc+1)) #fields = [field[1] for field in yt.load(react_data.output_files[0]).field_list] self.model.eval() - + with torch.no_grad(): losses = [] @@ -239,13 +305,9 @@ def do_prediction_vs_solution_plot(self): #for batch_idx, (data, targets) in enumerate(self.test_loader): pred = self.model(data_whole) - #print(pred.shape) - for i in range(pred.shape[0]): - if i == 0: - for j in range(pred.shape[1]): - plt.scatter(pred[i,j], targets_whole[i,j], color=colors[j], label=self.fields[j]) - else: - plt.scatter(pred[i, :self.nnuc+1], targets_whole[i, :self.nnuc+1], c=colors) + + for i in range(self.nnuc+1): + plt.scatter(pred[:, i], targets_whole[:, i], color=colors[i], label=self.fields[i]) self.model.train() diff --git a/maestroflame/maestroflame/pred_v_sol.jl b/maestroflame/maestroflame/pred_v_sol.jl new file mode 100644 index 0000000..85eb8e1 --- /dev/null +++ b/maestroflame/maestroflame/pred_v_sol.jl @@ -0,0 +1,51 @@ +using Pkg +using DelimitedFiles + +using Base +#Pkg.activate("julia_env") +#Pkg.add("GR") + + + +# using Plots +# +#println(pwd()) + + +#cut off pred_v_sol.jl +source_dir = chop(Base.source_path(), tail = 13) + + +pred = readdlm(source_dir * "python_to_julia_data/pred.txt") +labels = readdlm(source_dir * "python_to_julia_data/labels.txt") +targets = readdlm(source_dir * "python_to_julia_data/targets.txt") + +save_dir = labels[length(labels)] +#package_dir = labels[length(labels)] +labels = labels[1:length(labels)-1] + +#Pkg.activate(package_dir * "/julia_env") +#ENV["GRDIR"]="" +#Pkg.build("GR") +using Plots + + +labels = string.(labels) +labels = reshape(labels, (1, size(labels)[1]) ) + + +plotd = scatter(pred, targets, labels=labels, dpi=600) +savefig(plotd, save_dir * "julia_m2_prediction_vs_solution.png") +#we now cut out data below 0. Julia plotting can't plot log plots if there are negative +# or zero data i guess +#inds = (targets .> 0) .& (pred .> 0) + +#we now cut out data below 0. Julia plotting can't plot log plots if there are negative +# or zero data i guess. but to preserve shape, we just put all these points at (1,1) +inds = (targets .<= 0) .| (pred .<= 0) +targets[inds] .= 1 +pred[inds] .= 1 + + +plotd = scatter(targets, pred, xaxis=:log, yaxis=:log, labels=labels, dpi=600) +savefig(plotd, save_dir * "julia_m2_log_prediction_vs_solution.png") diff --git a/maestroflame/maestroflame/train.py b/maestroflame/maestroflame/train.py index 844cf51..8ed35f7 100644 --- a/maestroflame/maestroflame/train.py +++ b/maestroflame/maestroflame/train.py @@ -250,22 +250,6 @@ def train(self, model, optimizer, num_epochs, criterion, save_every_N=np.Inf): self.component_losses_train.append(component_loss/batch_idx) self.cost_per_epoc.append(sum(plotting_losses) / len(plotting_losses)) - with torch.no_grad(): - if epoch % save_every_N == 0 and epoch != 0: - directory = self.output_dir+'intermediate_output/epoch'+str(epoch)+'/' - os.mkdir(directory) - - - torch.save(model.state_dict(), directory+'my_model.pt') - np.savetxt(directory + "/cost_per_epoch.txt", self.cost_per_epoc) - np.savetxt(directory + "/component_losses_test.txt", self.component_losses_test) - np.savetxt(directory + "/component_losses_train.txt", self.component_losses_train) - - - plot_class = plotting_standard(model, self.fields, self.test_loader, self.cost_per_epoc, np.array(self.component_losses_test), - np.array(self.component_losses_train), self.cost_per_epoc_test, directory) - - plot_class.do_all_plots() if self.DO_PLOTTING: @@ -295,9 +279,30 @@ def train(self, model, optimizer, num_epochs, criterion, save_every_N=np.Inf): model.train() + + with torch.no_grad(): + if epoch % save_every_N == 0 and epoch != 0: + directory = self.output_dir+'intermediate_output/epoch'+str(epoch)+'/' + os.mkdir(directory) + + + torch.save(model.state_dict(), directory+'my_model.pt') + np.savetxt(directory + "/cost_per_epoch.txt", self.cost_per_epoc) + np.savetxt(directory + "/component_losses_test.txt", self.component_losses_test) + np.savetxt(directory + "/component_losses_train.txt", self.component_losses_train) + + + plot_class = plotting_standard(model, self.fields, self.test_loader, self.cost_per_epoc, np.array(self.component_losses_test), + np.array(self.component_losses_train), self.cost_per_epoc_test, directory) + + plot_class.do_all_plots() + + self.component_losses_test = np.array(self.component_losses_test) self.component_losses_train = np.array(self.component_losses_train) + + self.model = model if self.SAVE_MODEL: @@ -642,29 +647,6 @@ def criterion_plotting(prediction, targets): diff_losses = np.array(diff_losses) self.different_loss_metrics.append(diff_losses.sum(axis=0)/len(losses)) - with torch.no_grad(): - if epoch % save_every_N == 0 and epoch != 0: - directory = self.output_dir+'intermediate_output/epoch'+str(epoch)+'/' - os.mkdir(directory) - - - torch.save(model.state_dict(), directory+'my_model.pt') - np.savetxt(directory + "/cost_per_epoch.txt", self.cost_per_epoc) - np.savetxt(directory + "/component_losses_test.txt", self.component_losses_test) - np.savetxt(directory + "/component_losses_train.txt", self.component_losses_train) - np.savetxt(self.output_dir + "/d_component_losses_test.txt", self.d_component_losses_test) - np.savetxt(self.output_dir + "/d_component_losses_train.txt", self.d_component_losses_train) - - - plot_class = plotting_pinn(self.model, self.fields, self.test_loader, self.cost_per_epoc, - np.array(self.component_losses_test), np.array(self.component_losses_train), - np.array(self.d_component_losses_test), np.array(self.d_component_losses_train), - self.cost_per_epoc_test, np.array(self.different_loss_metrics), - self.output_dir) - - plot_class.do_all_plots() - - if self.DO_PLOTTING: @@ -715,6 +697,28 @@ def criterion_plotting(prediction, targets): self.component_losses_test.append(component_loss/batch_idx) self.d_component_losses_test.append(d_component_loss/batch_idx) + with torch.no_grad(): + if epoch % save_every_N == 0 and epoch != 0: + directory = self.output_dir+'intermediate_output/epoch'+str(epoch)+'/' + os.mkdir(directory) + + + torch.save(model.state_dict(), directory+'my_model.pt') + np.savetxt(directory + "/cost_per_epoch.txt", self.cost_per_epoc) + np.savetxt(directory + "/component_losses_test.txt", self.component_losses_test) + np.savetxt(directory + "/component_losses_train.txt", self.component_losses_train) + np.savetxt(self.output_dir + "/d_component_losses_test.txt", self.d_component_losses_test) + np.savetxt(self.output_dir + "/d_component_losses_train.txt", self.d_component_losses_train) + + + plot_class = plotting_pinn(self.model, self.fields, self.test_loader, self.cost_per_epoc, + np.array(self.component_losses_test), np.array(self.component_losses_train), + np.array(self.d_component_losses_test), np.array(self.d_component_losses_train), + self.cost_per_epoc_test, np.array(self.different_loss_metrics), + self.output_dir) + + plot_class.do_all_plots() + self.component_losses_train = np.array(self.component_losses_train) self.component_losses_test = np.array(self.component_losses_test) diff --git a/maestroflame/setup.py b/maestroflame/setup.py index 2a30430..ee19946 100644 --- a/maestroflame/setup.py +++ b/maestroflame/setup.py @@ -9,6 +9,8 @@ license='LICENSE.txt', description='Machine Learning interface for learning a MAESTROeX flame.', long_description=open('README.md').read(), + package_data={'': ['pred_v_sol.jl', 'julia_env/Manifest.toml', 'julia_env/Project.toml']}, + include_package_data=True, install_requires=[ "matplotlib==3.4.1", "optuna==2.8.0", diff --git a/maestroflame/tools/make_sysimage.jl b/maestroflame/tools/make_sysimage.jl new file mode 100644 index 0000000..9d60549 --- /dev/null +++ b/maestroflame/tools/make_sysimage.jl @@ -0,0 +1,7 @@ +import Pkg; +Pkg.add("PackageCompiler") +Pkg.add("Plots") +Pkg.add("PyCall") +using PackageCompiler, Plots, PyCall +create_sysimage(:Plots, sysimage_path="sys_plots.so") + diff --git a/maestroflame/tools/test_sysimage.py b/maestroflame/tools/test_sysimage.py new file mode 100644 index 0000000..a256486 --- /dev/null +++ b/maestroflame/tools/test_sysimage.py @@ -0,0 +1,30 @@ + +import os + + +from julia.api import LibJulia +api = LibJulia.load() +#api.sysimage = "sys_plots.so" +api.sysimage = "sys.so" +api.init_julia() + +#from julia import Base +from julia import Plots + +import numpy as np + + +x = np.zeros((5,5)) +y = np.zeros_like(x) + +for i in range(x.shape[0]): + for j in range(x.shape[1]): + x[i,j] = i + y[i,j] = j + +Plots.scatter(x,y, title="A Julia plot made with numpy data run from python!", dpi=600) +Plots.savefig('test.png') + + +print("Success! Created plot: test.png") +os.system("open test.png")