Unverified Commit ccd80c1f authored by Stephan Rave's avatar Stephan Rave Committed by GitHub

Merge pull request #1160 from pymor/nb_move

remove notebooks dir
parents f7de9eb1 52e900fc
Pipeline #68593 passed with stages
in 41 minutes
......@@ -285,78 +285,6 @@ mpi 3 8:
- ./.ci/gitlab/test_mpi.bash
- find . -name "coverage*"
- ls -la *
notebooks_dir 3 6:
extends: .pytest
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- when: on_success
variables:
COVERAGE_FILE: coverage_notebooks_dir__3.6
services:
- name: zivgitlab.wwu.io/pymor/docker/pymor/pypi-mirror_stable_py3.6:f6acb8bdf750d965c15f7f90b01fac4b745b58bd
alias: pypi_mirror
image: zivgitlab.wwu.io/pymor/docker/pymor/testing_py3.6:f6acb8bdf750d965c15f7f90b01fac4b745b58bd
script:
- |
if [[ "$CI_COMMIT_REF_NAME" == *"github/PR_"* ]]; then
echo selecting hypothesis profile "ci_pr" for branch $CI_COMMIT_REF_NAME
export PYMOR_HYPOTHESIS_PROFILE="ci_pr"
else
echo selecting hypothesis profile "ci" for branch $CI_COMMIT_REF_NAME
export PYMOR_HYPOTHESIS_PROFILE="ci"
fi
- ./.ci/gitlab/test_notebooks_dir.bash
- find . -name "coverage*"
- ls -la *
notebooks_dir 3 7:
extends: .pytest
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- when: on_success
variables:
COVERAGE_FILE: coverage_notebooks_dir__3.7
services:
- name: zivgitlab.wwu.io/pymor/docker/pymor/pypi-mirror_stable_py3.7:f6acb8bdf750d965c15f7f90b01fac4b745b58bd
alias: pypi_mirror
image: zivgitlab.wwu.io/pymor/docker/pymor/testing_py3.7:f6acb8bdf750d965c15f7f90b01fac4b745b58bd
script:
- |
if [[ "$CI_COMMIT_REF_NAME" == *"github/PR_"* ]]; then
echo selecting hypothesis profile "ci_pr" for branch $CI_COMMIT_REF_NAME
export PYMOR_HYPOTHESIS_PROFILE="ci_pr"
else
echo selecting hypothesis profile "ci" for branch $CI_COMMIT_REF_NAME
export PYMOR_HYPOTHESIS_PROFILE="ci"
fi
- ./.ci/gitlab/test_notebooks_dir.bash
- find . -name "coverage*"
- ls -la *
notebooks_dir 3 8:
extends: .pytest
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- when: on_success
variables:
COVERAGE_FILE: coverage_notebooks_dir__3.8
services:
- name: zivgitlab.wwu.io/pymor/docker/pymor/pypi-mirror_stable_py3.8:f6acb8bdf750d965c15f7f90b01fac4b745b58bd
alias: pypi_mirror
image: zivgitlab.wwu.io/pymor/docker/pymor/testing_py3.8:f6acb8bdf750d965c15f7f90b01fac4b745b58bd
script:
- |
if [[ "$CI_COMMIT_REF_NAME" == *"github/PR_"* ]]; then
echo selecting hypothesis profile "ci_pr" for branch $CI_COMMIT_REF_NAME
export PYMOR_HYPOTHESIS_PROFILE="ci_pr"
else
echo selecting hypothesis profile "ci" for branch $CI_COMMIT_REF_NAME
export PYMOR_HYPOTHESIS_PROFILE="ci"
fi
- ./.ci/gitlab/test_notebooks_dir.bash
- find . -name "coverage*"
- ls -la *
pip_installed 3 6:
extends: .pytest
rules:
......
......@@ -428,7 +428,7 @@ tpl = jinja2.Template(tpl)
pythons = ['3.6', '3.7', '3.8']
oldest = [pythons[0]]
newest = [pythons[-1]]
test_scripts = [("mpi", pythons, 1), ("notebooks_dir", pythons, 1), ("pip_installed", pythons, 1),
test_scripts = [("mpi", pythons, 1), ("pip_installed", pythons, 1),
("vanilla", pythons, 1), ("numpy_git", newest, 1), ("oldest", oldest, 1),]
# these should be all instances in the federation
binder_urls = [f'https://{sub}.mybinder.org/build/gh/pymor/pymor' for sub in ('gke', 'ovh', 'gesis')]
......
#!/bin/bash
THIS_DIR="$(cd "$(dirname ${BASH_SOURCE[0]})" ; pwd -P )"
source ${THIS_DIR}/common_test_setup.bash
xvfb-run -a py.test ${COMMON_PYTEST_OPTS} --cov=src/pymor notebooks/test.py
coverage xml
.ipynb_checkpoints/*
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/pymor/pymor/master)
{
"cells": [
{
"cell_type": "raw",
"metadata": {},
"source": [
"This file is part of the pyMOR project (http://www.pymor.org).\n",
"Copyright 2013-2020 pyMOR developers and contributors. All rights reserved.\n",
"License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create heat equation model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import scipy.linalg as spla\n",
"import scipy.sparse as sps\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from pymor.basic import *\n",
"from pymor.models.iosys import LinearDelayModel\n",
"from pymor.reductors.interpolation import DelayBHIReductor, TFBHIReductor"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"p = InstationaryProblem(\n",
" StationaryProblem(\n",
" domain=LineDomain([0.,1.], left='robin', right='robin'),\n",
" diffusion=ConstantFunction(1., 1),\n",
" robin_data=(ConstantFunction(1., 1), ExpressionFunction('(x[...,0] < 1e-10) * 1.', 1)),\n",
" outputs=(('l2_boundary', ExpressionFunction('(x[...,0] > (1 - 1e-10)) * 1.', 1)),)\n",
" ),\n",
" ConstantFunction(0., 1),\n",
" T=3.\n",
")\n",
"\n",
"fom, _ = discretize_instationary_cg(p, diameter=1/100, nt=100)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"lti = fom.to_lti()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Add delayed feedback from output to input"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tau = 1.\n",
"g = 5.\n",
"Atau = sps.coo_matrix(([g], ([0], [lti.order - 1])), (lti.order, lti.order)).tocsc()\n",
"Atau = NumpyMatrixOperator(Atau, source_id=lti.solution_space.id, range_id=lti.solution_space.id)\n",
"td_lti = LinearDelayModel(lti.A, (Atau,), (tau,), lti.B, lti.C, E=lti.E)\n",
"print(td_lti)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"w = np.logspace(-1, 2.5, 500)\n",
"td_lti.mag_plot(w, ax=ax)\n",
"ax.set_title('Magnitude plot of the FOM')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Unstructured Hermite interpolation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"interp = TFBHIReductor(td_lti)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"r = 3\n",
"sigma = np.logspace(0, 1, r)\n",
"sigma = np.concatenate((1j * sigma, -1j * sigma))\n",
"b = np.ones((2*r, td_lti.dim_input))\n",
"c = np.ones((2*r, td_lti.dim_output))\n",
"\n",
"rom = interp.reduce(sigma, b, c)\n",
"err_rom = td_lti - rom"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"td_lti.mag_plot(w, ax=ax)\n",
"rom.mag_plot(w, ax=ax)\n",
"ax.set_title('Magnitude plot of the FOM and ROM')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"err_rom.mag_plot(w, ax=ax)\n",
"ax.set_title('Magnitude plot of the error')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Delay-preserving reduction by Hermite interpolation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"delay_interp = DelayBHIReductor(td_lti)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"td_rom = delay_interp.reduce(sigma, b, c)\n",
"err_td_rom = td_lti - td_rom"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"td_lti.mag_plot(w, ax=ax)\n",
"rom.mag_plot(w, ax=ax)\n",
"td_rom.mag_plot(w, ax=ax)\n",
"ax.set_title('Magnitude plot of the FOM and ROMs')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"err_rom.mag_plot(w, ax=ax, color='tab:orange')\n",
"err_td_rom.mag_plot(w, ax=ax, color='tab:green')\n",
"ax.set_title('Magnitude plot of the errors')\n",
"plt.show()"
]
}
],
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"from pymor.analyticalproblems.domaindescriptions import RectDomain\n",
"from pymor.analyticalproblems.elliptic import StationaryProblem\n",
"from pymor.discretizers.builtin import discretize_stationary_cg\n",
"from pymor.analyticalproblems.functions import ExpressionFunction, LincombFunction\n",
"from pymor.parameters.functionals import ProjectionParameterFunctional, ExpressionParameterFunctional\n",
"from time import sleep\n",
"from ipywidgets import interact, widgets\n",
"from pythreejs._example_helper import use_example_model_ids\n",
"use_example_model_ids()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"rhs = ExpressionFunction('(x[..., 0] - 0.5)**2 * 1000', 2, ())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"problem = StationaryProblem(\n",
" domain=RectDomain(),\n",
" rhs=rhs,\n",
" diffusion=LincombFunction(\n",
" [ExpressionFunction('1 - x[..., 0]', 2, ()), ExpressionFunction('x[..., 0]', 2, ())],\n",
" [ProjectionParameterFunctional('diffusionl'), 1]\n",
" ),\n",
" parameter_ranges=(0.01, 0.1),\n",
" name='2DProblem'\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"lines_to_next_cell": 2,
"scrolled": true
},
"outputs": [],
"source": [
"args = {'N': 100, 'samples': 1}\n",
"m, data = discretize_stationary_cg(problem, diameter=1. / args['N'])\n",
"U = m.solution_space.empty()\n",
"for mu in problem.parameter_space.sample_uniformly(args['samples']):\n",
" U.append(m.solve(mu))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Us = U * 1.5\n",
"m.visualize((U, Us), title='Solution for diffusionl=0.5')\n"
]
}
],
"metadata": {
"jupytext": {
"formats": "ipynb,py:percent"
},
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pymor.basic import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"N = 100\n",
"\n",
"rhs = ExpressionFunction('(x - 0.5)**2 * 1000', 1, ())\n",
"\n",
"d0 = ExpressionFunction('1 - x', 1, ())\n",
"d1 = ExpressionFunction('x', 1, ())\n",
"\n",
"f0 = ProjectionParameterFunctional('diffusionl')\n",
"f1 = 1."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"problem = StationaryProblem(\n",
" domain=LineDomain(),\n",
" rhs=rhs,\n",
" diffusion=LincombFunction([d0, d1], [f0, f1]),\n",
" dirichlet_data=ConstantFunction(value=0, dim_domain=1),\n",
" name='1DProblem'\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parameter_space = problem.parameters.space(0.1, 1)\n",
"\n",
"discretizer = discretize_stationary_cg\n",
"m, data = discretizer(problem, diameter=1 / N)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"U = m.solution_space.empty()\n",
"for mu in parameter_space.sample_uniformly(10):\n",
" U.append(m.solve(mu))\n",
"m.visualize(U, title='Solution for diffusionl in [0.1, 1]', separate_plots=True, separate_axes=False)"
]
}
],
"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.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
This diff is collapsed.
{
"cells": [
{
"cell_type": "raw",
"metadata": {},
"source": [
"This file is part of the pyMOR project (http://www.pymor.org).\n",
"Copyright 2013-2020 pyMOR developers and contributors. All rights reserved.\n",
"License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import scipy.linalg as spla\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from pymor.basic import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def H(s, mu):\n",
" tau = mu['tau'][0]\n",
" return np.array([[np.exp(-s) / (tau * s + 1)]])\n",
"\n",
"def dH(s, mu):\n",
" tau = mu['tau'][0]\n",
" return np.array([[-(tau * s + tau + 1) * np.exp(-s) / (tau * s + 1) ** 2]])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fom = TransferFunction(1, 1,\n",
" H, dH,\n",
" parameters={'tau': 1})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Magnitude plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mu_list_short = [0.01, 0.1, 1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"w = np.logspace(-2, 4, 100)\n",
"\n",
"fig, ax = plt.subplots()\n",
"for mu in mu_list_short:\n",
" fom.mag_plot(w, ax=ax, mu=mu, label=fr'$\\tau = {mu}$')\n",
"ax.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"w_list = np.logspace(-2, 4, 100)\n",
"mu_list = np.logspace(-2, 0, 50)\n",
"\n",
"fom_w_mu = np.zeros((len(w_list), len(mu_list)))\n",
"for i, mu in enumerate(mu_list):\n",
" fom_w_mu[:, i] = spla.norm(fom.freq_resp(w_list, mu=mu), axis=(1, 2))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"out = ax.contourf(w_list, mu_list, fom_w_mu.T,\n",
" norm=mpl.colors.LogNorm(),\n",
" levels=np.logspace(np.log10(fom_w_mu.min()), np.log10(fom_w_mu.max()), 100))\n",
"ax.set_xlabel(r'Frequency $\\omega$')\n",
"ax.set_ylabel(r'Parameter $\\mu$')\n",
"ax.set_xscale('log')\n",
"ax.set_yscale('log')\n",
"fig.colorbar(out, ticks=np.logspace(-4, 1, 6))\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TF-IRKA"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],