Commit fff3efd0 authored by Theresa Pollinger's avatar Theresa Pollinger
Browse files

reorganized

parent b50d710a
This diff is collapsed.
#!/usr/bin/env python3
# http://cmd2.readthedocs.io
#import cmd2 as cmd
import sys
from ipykernel.kernelbase import Kernel
from ipykernel.comm import CommManager
......@@ -20,18 +20,26 @@ from pde_state_machine import *
class Interview(MetaKernel):
implementation = 'Interview'
implementation_version = '1.0'
language = 'no-op'
language = 'text'
language_version = '0.1'
language_info = {
'name': 'Any text',
'name': 'text',
'mimetype': 'text/plain',
'file_extension': '.txt',
'help_links': MetaKernel.help_links,
}
banner = "Interview kernel\n\n" \
"Hello, " + getpass.getuser() + "! I am " + "TheInterview" + ", your partial differential equations and simulations expert. " \
"Let's set up a simulation together.\n" \
"Please enter anything to start the interview."
# "How many dimensions does your model have?" #TODO this never shows in the notebook
#kernel_json = {
# "argv": [
# sys.executable, "-m", "interview_kernel", "-f", "{connection_file}"],
# "display_name": "Interview Kernel",
# "language": "text",
# "name": "interview_kernel"
#}
def __init__(self, **kwargs):
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, user! I am TheInterview, your partial differential equations and simulations expert. Let's set up a simulation together.\n",
"How many dimensions does your model have?\n",
"I am just assuming it's 1, since that is all we can currently handle.\n",
"\n",
"\n",
"What is the domain you would like to simulate for? Ω : type ❘ = [?;?], e.g. Ω = [0.0;1.0]\n",
"By the way, you can always try and use LaTeX-type input.\n"
]
}
],
"source": [
"anything"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"we will just assume that the variable is called x for now.\n",
"\n",
"\n",
"Which variable(s) are you looking for? / What are the unknowns in your model? u : Ω → ??, e.g., u : Ω → ℝ ?\n"
]
}
],
"source": [
"Ω = [0.0;1.0]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ok, u : Ω → ℝ\n",
"u : Ω → ℝ\n",
"\n",
"\n",
"Would you like to name additional parameters like constants or functions (that are independent of your unknowns)? c : ℝ = ? or f : Ω → ℝ = ?\n"
]
}
],
"source": [
"u : Ω → ℝ"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ok, f = [ x : Ω] x\n",
"Would you like to declare more parameters? [y/n]? \n"
]
}
],
"source": [
"f = x"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"y"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ok, α = [ x : Ω] -5.0\n",
"Would you like to declare more parameters? [y/n]? \n"
]
}
],
"source": [
"\\alpha = -5.0"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": []
}
],
"source": [
"y"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"I did not catch that. Could you please rephrase?\n",
"Details: MMT server error: unbound token: ·\n"
]
}
],
"source": [
"k = x \\cdot x"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"f = x\n",
"α = -5.0\n",
"\n",
"\n",
"Let's talk about your partial differential equation(s). What do they look like? Δu = 0.0, or laplace_operator Ω ℝ u = f ?\n"
]
}
],
"source": [
"n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ok, <result>\n",
" <xml>\n",
" <theory meta=\"http://mathhub.info/MitM/Foundation?Logic\" base=\"http://mathhub.info/MitM/smglom/calculus\" name=\"ephpde1\">\n",
" \n",
" \n",
" <import from=\"http://mathhub.info/MitM/smglom/calculus?mDifferentialOperators\"><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#0.0.0:32.0.32\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata></import><import from=\"http://mathhub.info/MitM/smglom/calculus?u\"><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#0.0.0:11.0.11\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata></import><import from=\"http://mathhub.info/MitM/smglom/calculus?f\"><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#0.0.0:11.0.11\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata></import><import from=\"http://mathhub.info/MitM/smglom/calculus?&#945;\"><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#0.0.0:11.0.11\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata></import><constant name=\"mylhs\">\n",
" <metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#1.0.1:35.0.35\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata>\n",
" <type><om:OMOBJ xmlns:om=\"http://www.openmath.org/OpenMath\"><om:OMBIND>\n",
" <om:OMS name=\"Pi\" module=\"LambdaPi\" base=\"http://cds.omdoc.org/urtheories\"/>\n",
" <om:OMBVAR><om:OMV name=\"anyu\"><type><om:OMA><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#19.0.19:23.0.23\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata>\n",
" <om:OMS name=\"arrow\" module=\"LambdaPi\" base=\"http://cds.omdoc.org/urtheories\"/>\n",
" <om:OMS name=\"&#937;\" module=\"ephdomain\" base=\"http://mathhub.info/MitM/smglom/calculus\"/><om:OMS name=\"real_lit\" module=\"RealLiterals\" base=\"http://mathhub.info/MitM/Foundation\"/>\n",
" </om:OMA></type></om:OMV></om:OMBVAR>\n",
" <om:OMA>\n",
" <om:OMS name=\"arrow\" module=\"LambdaPi\" base=\"http://cds.omdoc.org/urtheories\"/>\n",
" <om:OMS name=\"&#937;\" module=\"ephdomain\" base=\"http://mathhub.info/MitM/smglom/calculus\"/><om:OMS name=\"real_lit\" module=\"RealLiterals\" base=\"http://mathhub.info/MitM/Foundation\"/>\n",
" </om:OMA>\n",
" </om:OMBIND></om:OMOBJ></type>\n",
" <definition><om:OMOBJ xmlns:om=\"http://www.openmath.org/OpenMath\"><om:OMBIND><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#10.0.10:32.0.32\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata>\n",
" <om:OMS name=\"lambda\" module=\"LambdaPi\" base=\"http://cds.omdoc.org/urtheories\"/>\n",
" <om:OMBVAR><om:OMV name=\"anyu\"><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#12.0.12:15.0.15\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata><type><om:OMA><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#19.0.19:23.0.23\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata>\n",
" <om:OMS name=\"arrow\" module=\"LambdaPi\" base=\"http://cds.omdoc.org/urtheories\"/>\n",
" <om:OMS name=\"&#937;\" module=\"ephdomain\" base=\"http://mathhub.info/MitM/smglom/calculus\"/><om:OMS name=\"real_lit\" module=\"RealLiterals\" base=\"http://mathhub.info/MitM/Foundation\"/>\n",
" </om:OMA></type></om:OMV></om:OMBVAR>\n",
" <om:OMA><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#27.0.27:32.0.32\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata>\n",
" <om:OMS name=\"apply\" module=\"LambdaPi\" base=\"http://cds.omdoc.org/urtheories\"/>\n",
" <om:OMS name=\"laplace_operator\" module=\"mDifferentialOperators\" base=\"http://mathhub.info/MitM/smglom/calculus\"/><om:OMS name=\"&#937;\" module=\"ephdomain\" base=\"http://mathhub.info/MitM/smglom/calculus\"/><om:OMS name=\"real_lit\" module=\"RealLiterals\" base=\"http://mathhub.info/MitM/Foundation\"/><om:OMV name=\"anyu\"><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#29.0.29:32.0.32\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata></om:OMV>\n",
" </om:OMA>\n",
" </om:OMBIND></om:OMOBJ></definition>\n",
" \n",
" </constant><constant name=\"myrhs\">\n",
" <metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#1.0.1:12.0.12\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata>\n",
" <type><om:OMOBJ xmlns:om=\"http://www.openmath.org/OpenMath\"><om:OMBIND>\n",
" <om:OMS name=\"Pi\" module=\"LambdaPi\" base=\"http://cds.omdoc.org/urtheories\"/>\n",
" <om:OMBVAR><om:OMV name=\"x\"><type><om:OMS name=\"&#937;\" module=\"ephdomain\" base=\"http://mathhub.info/MitM/smglom/calculus\"/></type></om:OMV></om:OMBVAR>\n",
" <om:OMS name=\"real_lit\" module=\"RealLiterals\" base=\"http://mathhub.info/MitM/Foundation\"/>\n",
" </om:OMBIND></om:OMOBJ></type>\n",
" <definition><om:OMOBJ xmlns:om=\"http://www.openmath.org/OpenMath\"><om:OMS name=\"&#945;\" module=\"&#945;\" base=\"http://mathhub.info/MitM/smglom/calculus\"><metadata><link resource=\"http://mathhub.info/MitM/smglom/calculus#10.0.10:10.0.10\" rel=\"http://cds.omdoc.org/mmt?metadata?sourceRef\"/></metadata></om:OMS></om:OMOBJ></definition>\n",
" \n",
" </constant>\n",
" </theory>\n",
" </xml>\n",
"</result>\n",
"\n",
"\n",
"\n",
"These are all the PDEs needed.\n",
"Let's discuss your boundary conditions. What do they look like? u(x) = f(x) or u(1.0) = \\alpha ?\n"
]
}
],
"source": [
"Δu = \\alpha"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ok \n",
"\n",
"\n",
"These are all the boundary conditions needed.\n",
"Would you like to try and solve the PDE using the Finite Difference Method in ExaStencils? [y/n]? \n"
]
}
],
"source": [
"u = f"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generated ExaStencils input.\n"
]
}
],
"source": [
"y"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Interview",
"language": "text",
"name": "echo"
},
"language_info": {
"file_extension": ".txt",
"mimetype": "text/plain",
"name": "Any text"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -42,7 +42,6 @@ def start_mmt_extension(port_number, mmtjar, timeout=3.0):
"extension", "info.kwarc.mmt.interviews.InterviewServer"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if completed.stdout != None and "(Connection refused)" in str(completed.stdout):
print("connection refused")
if timeout > 0.0:
start_mmt_extension(port_number, mmtjar, timeout-0.1)
else:
......
......@@ -795,6 +795,65 @@ class PDE_States:
self.exaout.create_output(self.simdata)
self.poutput("Generated ExaStencils input.")
# TODO generate and run simulation
# display solution using matplotlib
# cf.https://github.com/ipython/ipython/blob/6a5220d032f5a60267b051783721aa0d5a0e3373/IPython/core/magics/pylab.py
import matplotlib
matplotlib.use('nbagg')
import matplotlib.pyplot as plt
#from ipykernel.core import InteractiveShell
plt.ion()
#try:
# gui, backend = self.shell.enable_matplotlib("nbagg")
#except Exception as e:
# raise InterviewError("Unable to use matplotlib for display, sorry! \n" + e.args[0])
plt.plot([1, 2, 3])
def enable_matplotlib(self, gui=None):
"""Enable interactive matplotlib and inline figure support.
stolen from
https://github.com/ipython/ipython/blob/35a4f43a1bbcd371d6f917e6a2c258848df6e47d/IPython/core/interactiveshell.py .
This takes the following steps:
1. select the appropriate eventloop and matplotlib backend
2. set up matplotlib for interactive use with that backend
3. configure formatters for inline figure display
4. enable the selected gui eventloop
Parameters
----------
gui : optional, string
If given, dictates the choice of matplotlib GUI backend to use
(should be one of IPython's supported backends, 'qt', 'osx', 'tk',
'gtk', 'wx' or 'inline'), otherwise we use the default chosen by
matplotlib (as dictated by the matplotlib build-time options plus the
user's matplotlibrc configuration file). Note that not all backends
make sense in all contexts, for example a terminal ipython can't
display figures inline.
"""
from IPython.core import pylabtools as pt
gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
if gui != 'inline':
# If we have our first gui selection, store it
if self.pylab_gui_select is None:
self.pylab_gui_select = gui
# Otherwise if they are different
elif gui != self.pylab_gui_select:
print('Warning: Cannot change to a different GUI toolkit: %s.'
' Using %s instead.' % (gui, self.pylab_gui_select))
gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
pt.activate_matplotlib(backend)
pt.configure_inline_support(self, backend)
# Now we must activate the gui pylab wants to use, and fix %run to take
# plot updates into account
self.enable_gui(gui)
self.magics_manager.registry['ExecutionMagics'].default_runner = \
pt.mpl_runner(self.safe_execfile)
return gui, backend
def sim_ok_fd(self):
self.simdata["sim"]["type"] = "FiniteDifferences"
......@@ -847,8 +906,8 @@ class PDE_States:
except MMTServerError as error:
# self.poutput("no backend available that is applicable to " + "http://mathhub.info/MitM/smglom/calculus" + "?" + re.split('AS', dictentry["viewname"])[-1] + "?")
# we are expecting errors if we try to include something that is not referenced in the source theory, so ignore them
if ("no backend available that is applicable to " + "http://mathhub.info/MitM/smglom/calculus" +
"?" + re.split('AS', current_view_name)[-1] + "?" ) in error.args[0]:
expected_str = "no backend available that is applicable to " + "http://mathhub.info/MitM/smglom/calculus" + "?" + re.split('AS', current_view_name)[-1] + "?"
if expected_str not in error.args[0]:
raise
def construct_current_view_name(self, dictentry):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment