Chapter 3: Markov Dynamics#
inventory_sim.py#
Show code cell source
import numpy as np
from scipy.stats import geom
from itertools import product
from quantecon import MarkovChain
from collections import namedtuple
# NamedTuple Model
Model = namedtuple("Model", ("S", "s", "p", "φ", "h"))
def create_inventory_model(S=100, # Order size
s=10, # Order threshold
p=0.4): # Demand parameter
φ = geom(p, loc=-1) # loc sets support to {0,1,...}
h = lambda x, d: max(x - d, 0) + S*(x <= s)
return Model(S=S, s=s, p=p, φ=φ, h=h)
def sim_inventories(model, ts_length=200):
"""Simulate the inventory process."""
S, s, p, φ, h = model
X = np.empty(ts_length)
X[0] = S # Initial condition
for t in range(0, ts_length - 1):
X[t+1] = h(X[t], φ.rvs())
return X
def compute_mc(model, d_max=100):
"""Compute the transition probabilities and state."""
S, s, p, φ, h = model
n = S + s + 1 # Size of state space
state_vals = np.arange(n)
P = np.empty((n, n))
for (i, j) in product(range(0, n), range(0, n)):
P[i, j] = sum((h(i, d) == j)*φ.pmf(d) for d in range(d_max+1))
return MarkovChain(P, state_vals)
def compute_stationary_dist(model):
"""Compute the stationary distribution of the model."""
mc = compute_mc(model)
return mc.state_values, mc.stationary_distributions[0]
# Plots
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
plt.rcParams.update({"text.usetex": True, "font.size": 14})
default_model = create_inventory_model()
def plot_ts(model, fontsize=16,
figname="figures/inventory_sim_1.pdf",
savefig=False):
S, s, p, φ, h = model
X = sim_inventories(model)
fig, ax = plt.subplots(figsize=(9, 5.2))
ax.plot(X, label=r"$X_t$", linewidth=3, alpha=0.6)
fontdict = {'fontsize': fontsize}
ax.set_xlabel(r"$t$", fontdict=fontdict)
ax.set_ylabel("inventory", fontdict=fontdict)
ax.legend(fontsize=fontsize, frameon=False)
ax.set_ylim(0, S + s + 20)
if savefig:
fig.savefig(figname)
def plot_hist(model, fontsize=16,
figname="figures/inventory_sim_2.pdf",
savefig=False):
S, s, p, φ, h = model
state_values, ψ_star = compute_stationary_dist(model)
X = sim_inventories(model, 1_000_000)
histogram = [np.mean(X == i) for i in state_values]
fig, ax = plt.subplots(figsize=(9, 5.2))
ax.plot(state_values, ψ_star, "k-", linewidth=3, alpha=0.7,
label=r"$\psi^*$")
ax.bar(state_values, histogram, alpha=0.7, label="frequency")
fontdict = {'fontsize': fontsize}
ax.set_xlabel("state", fontdict=fontdict)
ax.legend(fontsize=fontsize, frameon=False)
ax.set_ylim(0, 0.015)
if savefig:
fig.savefig(figname)
model = create_inventory_model()
plot_ts(model)
Error in callback <function _draw_all_if_interactive at 0x7f2c85f09750> (for post_execute):
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/pyplot.py:120, in _draw_all_if_interactive()
118 def _draw_all_if_interactive():
119 if matplotlib.is_interactive():
--> 120 draw_all()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/_pylab_helpers.py:132, in Gcf.draw_all(cls, force)
130 for manager in cls.get_all_fig_managers():
131 if force or manager.canvas.figure.stale:
--> 132 manager.canvas.draw_idle()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2082, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
2080 if not self._is_idle_drawing:
2081 with self._idle_draw_cntx():
-> 2082 self.draw(*args, **kwargs)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:400, in FigureCanvasAgg.draw(self)
396 # Acquire a lock on the shared font cache.
397 with RendererAgg.lock, \
398 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
399 else nullcontext()):
--> 400 self.figure.draw(self.renderer)
401 # A GUI class may be need to update a window using this draw, so
402 # don't forget to call the superclass.
403 super().draw()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/formatters.py:340, in BaseFormatter.__call__(self, obj)
338 pass
339 else:
--> 340 return printer(obj)
341 # Finally look for special method names
342 method = get_real_method(obj, self.print_method)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
149 from matplotlib.backend_bases import FigureCanvasBase
150 FigureCanvasBase(fig)
--> 152 fig.canvas.print_figure(bytes_io, **kw)
153 data = bytes_io.getvalue()
154 if fmt == 'svg':
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2342, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2336 renderer = _get_renderer(
2337 self.figure,
2338 functools.partial(
2339 print_method, orientation=orientation)
2340 )
2341 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2342 self.figure.draw(renderer)
2344 if bbox_inches:
2345 if bbox_inches == "tight":
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
<Figure size 900x520 with 1 Axes>
plot_hist(model)
Error in callback <function _draw_all_if_interactive at 0x7f2c85f09750> (for post_execute):
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/pyplot.py:120, in _draw_all_if_interactive()
118 def _draw_all_if_interactive():
119 if matplotlib.is_interactive():
--> 120 draw_all()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/_pylab_helpers.py:132, in Gcf.draw_all(cls, force)
130 for manager in cls.get_all_fig_managers():
131 if force or manager.canvas.figure.stale:
--> 132 manager.canvas.draw_idle()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2082, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
2080 if not self._is_idle_drawing:
2081 with self._idle_draw_cntx():
-> 2082 self.draw(*args, **kwargs)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:400, in FigureCanvasAgg.draw(self)
396 # Acquire a lock on the shared font cache.
397 with RendererAgg.lock, \
398 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
399 else nullcontext()):
--> 400 self.figure.draw(self.renderer)
401 # A GUI class may be need to update a window using this draw, so
402 # don't forget to call the superclass.
403 super().draw()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/formatters.py:340, in BaseFormatter.__call__(self, obj)
338 pass
339 else:
--> 340 return printer(obj)
341 # Finally look for special method names
342 method = get_real_method(obj, self.print_method)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
149 from matplotlib.backend_bases import FigureCanvasBase
150 FigureCanvasBase(fig)
--> 152 fig.canvas.print_figure(bytes_io, **kw)
153 data = bytes_io.getvalue()
154 if fmt == 'svg':
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2342, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2336 renderer = _get_renderer(
2337 self.figure,
2338 functools.partial(
2339 print_method, orientation=orientation)
2340 )
2341 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2342 self.figure.draw(renderer)
2344 if bbox_inches:
2345 if bbox_inches == "tight":
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
<Figure size 900x520 with 1 Axes>
is_irreducible.py#
Show code cell source
from quantecon import MarkovChain
import numpy as np
P = np.array([
[0.1, 0.9],
[0.0, 1.0]
])
mc = MarkovChain(P)
print(mc.is_irreducible)
False
laborer_sim.py#
Show code cell source
import numpy as np
from collections import namedtuple
# NamedTuple Model
Model = namedtuple("Model", ("α", "β"))
def create_laborer_model(α=0.3, β=0.2):
return Model(α=α, β=β)
def laborer_update(x, model): # update X from t to t+1
if x == 1:
x_ = 2 if np.random.rand() < model.α else 1
else:
x_ = 1 if np.random.rand() < model.β else 2
return x_
def sim_chain(k, p, model):
X = np.empty(k)
X[0] = 1 if np.random.rand() < p else 2
for t in range(0, k-1):
X[t+1] = laborer_update(X[t], model)
return X
def test_convergence(k=10_000_000, p=0.5):
model = create_laborer_model()
α, β = model
ψ_star = (1/(α + β)) * np.array([β, α])
X = sim_chain(k, p, model)
ψ_e = (1/k) * np.array([sum(X == 1), sum(X == 2)])
error = np.max(np.abs(ψ_star - ψ_e))
approx_equal = np.allclose(ψ_star, ψ_e, rtol=0.01)
print(f"Sup norm deviation is {error}")
print(f"Approximate equality is {approx_equal}")
markov_js.py#
Show code cell source
"""
Infinite-horizon job search with Markov wage draws.
"""
from quantecon.markov import tauchen
import numpy as np
from collections import namedtuple
from s_approx import successive_approx
# NamedTuple Model
Model = namedtuple("Model", ("n", "w_vals", "P", "β", "c"))
def create_markov_js_model(
n=200, # wage grid size
ρ=0.9, # wage persistence
ν=0.2, # wage volatility
β=0.98, # discount factor
c=1.0 # unemployment compensation
):
"""
Creates an instance of the job search model with Markov wages.
"""
mc = tauchen(n, ρ, ν)
w_vals, P = np.exp(mc.state_values), mc.P
return Model(n=n, w_vals=w_vals, P=P, β=β, c=c)
def T(v, model):
"""
The Bellman operator Tv = max{e, c + β P v} with e(w) = w / (1-β).
"""
n, w_vals, P, β, c = model
h = c + β * np.dot(P, v)
e = w_vals / (1 - β)
return np.maximum(e, h)
def get_greedy(v, model):
"""Get a v-greedy policy."""
n, w_vals, P, β, c = model
σ = w_vals / (1 - β) >= c + β * np.dot(P, v)
return σ
def vfi(model):
"""Solve the infinite-horizon Markov job search model by VFI."""
v_init = np.zeros(model.w_vals.shape)
v_star = successive_approx(lambda v: T(v, model), v_init)
σ_star = get_greedy(v_star, model)
return v_star, σ_star
# == Policy iteration == #
def get_value(σ, model):
"""Get the value of policy σ."""
n, w_vals, P, β, c = model
e = w_vals / (1 - β)
K_σ = β * ((1 - σ) * P.T).T
r_σ = σ * e + (1 - σ) * c
I = np.identity(K_σ.shape[0])
return np.linalg.solve((I - K_σ), r_σ)
def policy_iteration(model):
"""
Howard policy iteration routine.
"""
σ = np.zeros(model.n, dtype=bool)
i, error = 0, True
while error:
v_σ = get_value(σ, model)
σ_new = get_greedy(v_σ, model)
error = np.any(σ_new ^ σ)
σ = σ_new
i = i + 1
print(f"Concluded loop {i} with error: {error}.")
return σ
# == Plots == #
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
plt.rcParams.update({"text.usetex": True, "font.size": 14})
default_model = create_markov_js_model()
def plot_main(model=default_model,
method="vfi",
savefig=False,
figname="figures/markov_js_vfix.png"):
n, w_vals, P, β, c = model
if method == "vfi":
v_star, σ_star = vfi(model)
else:
σ_star = policy_iteration(model)
v_star = get_value(σ_star, model)
h_star = c + β * np.dot(P, v_star)
e = w_vals / (1 - β)
fig, ax = plt.subplots(figsize=(9, 5.2))
ax.plot(w_vals, h_star, linewidth=4, ls="--", alpha=0.4, label=r"$h^*(w)$")
ax.plot(w_vals, e, linewidth=4, ls="--", alpha=0.4, label=r"$w/(1-\beta)$")
ax.plot(w_vals, np.maximum(e, h_star), "k-", alpha=0.7, label=r"$v^*(w)$")
ax.legend(frameon=False)
ax.set_xlabel(r"$w$")
if savefig:
fig.savefig(figname)
plot_main()
Completed iteration 25 with error 0.7358325123867075.
Completed iteration 50 with error 0.21393801675841218.
Completed iteration 75 with error 0.07487776205154262.
Completed iteration 100 with error 0.027611709626711445.
Completed iteration 125 with error 0.010342258331789367.
Completed iteration 150 with error 0.00392782716204465.
Completed iteration 175 with error 0.0014931447809232168.
Completed iteration 200 with error 0.0005676247519517119.
Completed iteration 225 with error 0.00021578485559814453.
Completed iteration 250 with error 8.203149057806058e-05.
Completed iteration 275 with error 3.1184604821987705e-05.
Completed iteration 300 with error 1.1854954394152628e-05.
Completed iteration 325 with error 4.506709132101605e-06.
Completed iteration 350 with error 1.713243804601916e-06.
Terminated successfully in 365 iterations.
Error in callback <function _draw_all_if_interactive at 0x7f2c85f09750> (for post_execute):
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/pyplot.py:120, in _draw_all_if_interactive()
118 def _draw_all_if_interactive():
119 if matplotlib.is_interactive():
--> 120 draw_all()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/_pylab_helpers.py:132, in Gcf.draw_all(cls, force)
130 for manager in cls.get_all_fig_managers():
131 if force or manager.canvas.figure.stale:
--> 132 manager.canvas.draw_idle()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2082, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
2080 if not self._is_idle_drawing:
2081 with self._idle_draw_cntx():
-> 2082 self.draw(*args, **kwargs)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:400, in FigureCanvasAgg.draw(self)
396 # Acquire a lock on the shared font cache.
397 with RendererAgg.lock, \
398 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
399 else nullcontext()):
--> 400 self.figure.draw(self.renderer)
401 # A GUI class may be need to update a window using this draw, so
402 # don't forget to call the superclass.
403 super().draw()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/formatters.py:340, in BaseFormatter.__call__(self, obj)
338 pass
339 else:
--> 340 return printer(obj)
341 # Finally look for special method names
342 method = get_real_method(obj, self.print_method)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
149 from matplotlib.backend_bases import FigureCanvasBase
150 FigureCanvasBase(fig)
--> 152 fig.canvas.print_figure(bytes_io, **kw)
153 data = bytes_io.getvalue()
154 if fmt == 'svg':
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2342, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2336 renderer = _get_renderer(
2337 self.figure,
2338 functools.partial(
2339 print_method, orientation=orientation)
2340 )
2341 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2342 self.figure.draw(renderer)
2344 if bbox_inches:
2345 if bbox_inches == "tight":
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
<Figure size 900x520 with 1 Axes>
markov_js_with_sep.py#
Show code cell source
"""
Infinite-horizon job search with Markov wage draws and separation.
"""
from quantecon.markov import tauchen
import numpy as np
from collections import namedtuple
from s_approx import successive_approx
# NamedTuple Model
Model = namedtuple("Model", ("n", "w_vals", "P", "β", "c", "α"))
def create_js_with_sep_model(
n=200, # wage grid size
ρ=0.9, ν=0.2, # wage persistence and volatility
β=0.98, α=0.1, # discount factor and separation rate
c=1.0): # unemployment compensation
"""Creates an instance of the job search model with separation."""
mc = tauchen(n, ρ, ν)
w_vals, P = np.exp(mc.state_values), mc.P
return Model(n=n, w_vals=w_vals, P=P, β=β, c=c, α=α)
def T(v, model):
"""The Bellman operator for the value of being unemployed."""
n, w_vals, P, β, c, α = model
d = 1 / (1 - β * (1 - α))
accept = d * (w_vals + α * β * np.dot(P, v))
reject = c + β * np.dot(P, v)
return np.maximum(accept, reject)
def get_greedy(v, model):
""" Get a v-greedy policy."""
n, w_vals, P, β, c, α = model
d = 1 / (1 - β * (1 - α))
accept = d * (w_vals + α * β * np.dot(P, v))
reject = c + β * np.dot(P, v)
σ = accept >= reject
return σ
def vfi(model):
"""Solve by VFI."""
v_init = np.zeros(model.w_vals.shape)
v_star = successive_approx(lambda v: T(v, model), v_init)
σ_star = get_greedy(v_star, model)
return v_star, σ_star
# == Plots == #
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
plt.rcParams.update({"text.usetex": True, "font.size": 14})
default_model = create_js_with_sep_model()
def plot_main(model=default_model,
savefig=False,
figname="figures/markov_js_with_sep_1.pdf"):
n, w_vals, P, β, c, α = model
v_star, σ_star = vfi(model)
d = 1 / (1 - β * (1 - α))
accept = d * (w_vals + α * β * np.dot(P, v_star))
h_star = c + β * np.dot(P, v_star)
w_star = np.inf
for (i, w) in enumerate(w_vals):
if accept[i] >= h_star[i]:
w_star = w
break
assert w_star != np.inf, "Agent never accepts"
fig, ax = plt.subplots(figsize=(9, 5.2))
ax.plot(w_vals, h_star, linewidth=4, ls="--", alpha=0.4,
label="continuation value")
ax.plot(w_vals, accept, linewidth=4, ls="--", alpha=0.4,
label="stopping value")
ax.plot(w_vals, v_star, "k-", alpha=0.7, label=r"$v_u^*(w)$")
ax.legend(frameon=False)
ax.set_xlabel(r"$w$")
if savefig:
fig.savefig(figname)
def plot_w_stars(α_vals=np.linspace(0.0, 1.0, 10),
savefig=False,
figname="figures/markov_js_with_sep_2.pdf"):
w_star_vec = np.empty_like(α_vals)
for (i_α, α) in enumerate(α_vals):
print(i_α, α)
model = create_js_with_sep_model(α=α)
n, w_vals, P, β, c, α = model
v_star, σ_star = vfi(model)
d = 1 / (1 - β * (1 - α))
accept = d * (w_vals + α * β * np.dot(P, v_star))
h_star = c + β * np.dot(P, v_star)
w_star = np.inf
for (i_w, w) in enumerate(w_vals):
if accept[i_w] >= h_star[i_w]:
w_star = w
break
assert w_star != np.inf, "Agent never accepts"
w_star_vec[i_α] = w_star
fig, ax = plt.subplots(figsize=(9, 5.2))
ax.plot(α_vals, w_star_vec, linewidth=2, alpha=0.6,
label="reservation wage")
ax.legend(frameon=False)
ax.set_xlabel(r"$\alpha$")
ax.set_xlabel(r"$w$")
if savefig:
fig.savefig(figname)
plot_main()
Completed iteration 25 with error 1.0768067726007757.
Completed iteration 50 with error 0.3114311653737616.
Completed iteration 75 with error 0.10927534292912355.
Completed iteration 100 with error 0.04148769976492872.
Completed iteration 125 with error 0.016208489343711108.
Completed iteration 150 with error 0.00636718413682047.
Completed iteration 175 with error 0.002501707451486368.
Completed iteration 200 with error 0.000989361244521092.
Completed iteration 225 with error 0.0003952811634491127.
Completed iteration 250 with error 0.0001580316448865915.
Completed iteration 275 with error 6.318165887364557e-05.
Completed iteration 300 with error 2.526028629290522e-05.
Completed iteration 325 with error 1.0099166189547759e-05.
Completed iteration 350 with error 4.037688142943807e-06.
Completed iteration 375 with error 1.6142843008992713e-06.
Terminated successfully in 390 iterations.
Error in callback <function _draw_all_if_interactive at 0x7f2c85f09750> (for post_execute):
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/pyplot.py:120, in _draw_all_if_interactive()
118 def _draw_all_if_interactive():
119 if matplotlib.is_interactive():
--> 120 draw_all()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/_pylab_helpers.py:132, in Gcf.draw_all(cls, force)
130 for manager in cls.get_all_fig_managers():
131 if force or manager.canvas.figure.stale:
--> 132 manager.canvas.draw_idle()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2082, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
2080 if not self._is_idle_drawing:
2081 with self._idle_draw_cntx():
-> 2082 self.draw(*args, **kwargs)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:400, in FigureCanvasAgg.draw(self)
396 # Acquire a lock on the shared font cache.
397 with RendererAgg.lock, \
398 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
399 else nullcontext()):
--> 400 self.figure.draw(self.renderer)
401 # A GUI class may be need to update a window using this draw, so
402 # don't forget to call the superclass.
403 super().draw()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/formatters.py:340, in BaseFormatter.__call__(self, obj)
338 pass
339 else:
--> 340 return printer(obj)
341 # Finally look for special method names
342 method = get_real_method(obj, self.print_method)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
149 from matplotlib.backend_bases import FigureCanvasBase
150 FigureCanvasBase(fig)
--> 152 fig.canvas.print_figure(bytes_io, **kw)
153 data = bytes_io.getvalue()
154 if fmt == 'svg':
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2342, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2336 renderer = _get_renderer(
2337 self.figure,
2338 functools.partial(
2339 print_method, orientation=orientation)
2340 )
2341 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2342 self.figure.draw(renderer)
2344 if bbox_inches:
2345 if bbox_inches == "tight":
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
<Figure size 900x520 with 1 Axes>
plot_w_stars()
0 0.0
Completed iteration 25 with error 0.7358325123867075.
Completed iteration 50 with error 0.21393801675841218.
Completed iteration 75 with error 0.07487776205154262.
Completed iteration 100 with error 0.027611709626711445.
Completed iteration 125 with error 0.010342258331789367.
Completed iteration 150 with error 0.00392782716204465.
Completed iteration 175 with error 0.0014931447809232168.
Completed iteration 200 with error 0.0005676247519517119.
Completed iteration 225 with error 0.00021578485559814453.
Completed iteration 250 with error 8.203149057806058e-05.
Completed iteration 275 with error 3.1184604821987705e-05.
Completed iteration 300 with error 1.1854954394152628e-05.
Completed iteration 325 with error 4.506709132101605e-06.
Completed iteration 350 with error 1.713243804601916e-06.
Terminated successfully in 365 iterations.
1 0.1111111111111111
Completed iteration 25 with error 1.0908342197011365.
Completed iteration 50 with error 0.3207246338823424.
Completed iteration 75 with error 0.11318340744479372.
Completed iteration 100 with error 0.04326081621015021.
Completed iteration 125 with error 0.01702270454350696.
Completed iteration 150 with error 0.006738975380415013.
Completed iteration 175 with error 0.0026685293016583955.
Completed iteration 200 with error 0.0010679313731145612.
Completed iteration 225 with error 0.0004299980392232783.
Completed iteration 250 with error 0.00017318107607877664.
Completed iteration 275 with error 6.974899999079298e-05.
Completed iteration 300 with error 2.8091546738551187e-05.
Completed iteration 325 with error 1.1313925725175977e-05.
Completed iteration 350 with error 4.556705860636612e-06.
Completed iteration 375 with error 1.8352222355133563e-06.
Terminated successfully in 393 iterations.
2 0.2222222222222222
Completed iteration 25 with error 1.1302039661879064.
Completed iteration 50 with error 0.40190677446813794.
Completed iteration 75 with error 0.15417026004176648.
Completed iteration 100 with error 0.06350128466102234.
Completed iteration 125 with error 0.026934357233869832.
Completed iteration 150 with error 0.011580448768086171.
Completed iteration 175 with error 0.0050026366601017.
Completed iteration 200 with error 0.0021615971167534553.
Completed iteration 225 with error 0.0009340178864860604.
Completed iteration 250 with error 0.0004035857706625734.
Completed iteration 275 with error 0.00017438796437119208.
Completed iteration 300 with error 7.535241419276417e-05.
Completed iteration 325 with error 3.255950799996299e-05.
Completed iteration 350 with error 1.4068846688530812e-05.
Completed iteration 375 with error 6.079098213263023e-06.
Completed iteration 400 with error 2.6267565402804394e-06.
Completed iteration 425 with error 1.135012084318987e-06.
Terminated successfully in 430 iterations.
3 0.3333333333333333
Completed iteration 25 with error 1.082781806027267.
Completed iteration 50 with error 0.45519415974240474.
Completed iteration 75 with error 0.19282144291682357.
Completed iteration 100 with error 0.08581200863319793.
Completed iteration 125 with error 0.039157737964949035.
Completed iteration 150 with error 0.01805454739234591.
Completed iteration 175 with error 0.00838563508999357.
Completed iteration 200 with error 0.003898038044262364.
Completed iteration 225 with error 0.0018120704587545333.
Completed iteration 250 with error 0.0008423743598768851.
Completed iteration 275 with error 0.00039159330419380467.
Completed iteration 300 with error 0.00018203939284688886.
Completed iteration 325 with error 8.462437999412487e-05.
Completed iteration 350 with error 3.9339208811384196e-05.
Completed iteration 375 with error 1.8287559086616056e-05.
Completed iteration 400 with error 8.501310219344305e-06.
Completed iteration 425 with error 3.951991345729766e-06.
Completed iteration 450 with error 1.8371563044183858e-06.
Terminated successfully in 471 iterations.
4 0.4444444444444444
Completed iteration 25 with error 1.0101061095615904.
Completed iteration 50 with error 0.48366451069681204.
Completed iteration 75 with error 0.2245641250651147.
Completed iteration 100 with error 0.10739554585371991.
Completed iteration 125 with error 0.052283813599210305.
Completed iteration 150 with error 0.025665632138029082.
Completed iteration 175 with error 0.012671593196692754.
Completed iteration 200 with error 0.00626138069863913.
Completed iteration 225 with error 0.0030940523821314514.
Completed iteration 250 with error 0.0015289256308008703.
Completed iteration 275 with error 0.0007555185499654726.
Completed iteration 300 with error 0.00037333947034312587.
Completed iteration 325 with error 0.00018448568895479411.
Completed iteration 350 with error 9.116359809979713e-05.
Completed iteration 375 with error 4.5048489489829535e-05.
Completed iteration 400 with error 2.226070982658257e-05.
Completed iteration 425 with error 1.1000129170213313e-05.
Completed iteration 450 with error 5.435713518409102e-06.
Completed iteration 475 with error 2.68605767672625e-06.
Completed iteration 500 with error 1.3273153314230512e-06.
Terminated successfully in 512 iterations.
5 0.5555555555555556
Completed iteration 25 with error 0.9354993514006864.
Completed iteration 50 with error 0.49436451425174255.
Completed iteration 75 with error 0.24818960566408776.
Completed iteration 100 with error 0.12648987573435022.
Completed iteration 125 with error 0.06517289125884673.
Completed iteration 150 with error 0.03378604797021012.
Completed iteration 175 with error 0.017566215840986388.
Completed iteration 200 with error 0.00915584797562019.
Completed iteration 225 with error 0.004772835312394363.
Completed iteration 250 with error 0.002488041947152908.
Completed iteration 275 with error 0.001296997585946258.
Completed iteration 300 with error 0.0006761151259055964.
Completed iteration 325 with error 0.00035245375121206735.
Completed iteration 350 with error 0.0001837315007549023.
Completed iteration 375 with error 9.577785525749505e-05.
Completed iteration 400 with error 4.992827860661464e-05.
Completed iteration 425 with error 2.60272376877424e-05.
Completed iteration 450 with error 1.3567804067804445e-05.
Completed iteration 475 with error 7.072794652174252e-06.
Completed iteration 500 with error 3.686994872964533e-06.
Completed iteration 525 with error 1.9220028093513974e-06.
Completed iteration 550 with error 1.0019256606597082e-06.
Terminated successfully in 552 iterations.
6 0.6666666666666666
Completed iteration 25 with error 0.904928287097114.
Completed iteration 50 with error 0.4935393062159932.
Completed iteration 75 with error 0.2642254156191157.
Completed iteration 100 with error 0.1422057238442065.
Completed iteration 125 with error 0.07698303775877946.
Completed iteration 150 with error 0.04180499616060729.
Completed iteration 175 with error 0.022759933588368142.
Completed iteration 200 with error 0.012395733168744982.
Completed iteration 225 with error 0.006751179539278951.
Completed iteration 250 with error 0.003676948092248722.
Completed iteration 275 with error 0.0020026053292028223.
Completed iteration 300 with error 0.001090694788466351.
Completed iteration 325 with error 0.0005940337342735802.
Completed iteration 350 with error 0.00032353329382317497.
Completed iteration 375 with error 0.0001762084982104284.
Completed iteration 400 with error 9.596982887671857e-05.
Completed iteration 425 with error 5.226880737296824e-05.
Completed iteration 450 with error 2.8467574225032877e-05.
Completed iteration 475 with error 1.5504520249010056e-05.
Completed iteration 500 with error 8.444349539615814e-06.
Completed iteration 525 with error 4.59911291983417e-06.
Completed iteration 550 with error 2.5048512597436456e-06.
Completed iteration 575 with error 1.3642369722788317e-06.
Terminated successfully in 589 iterations.
7 0.7777777777777777
Completed iteration 25 with error 0.8754680641411525.
Completed iteration 50 with error 0.48591938913980925.
Completed iteration 75 with error 0.2739472364400086.
Completed iteration 100 with error 0.15435613754701194.
Completed iteration 125 with error 0.08716896006367847.
Completed iteration 150 with error 0.04929986845724699.
Completed iteration 175 with error 0.027901732615987385.
Completed iteration 200 with error 0.01580799147810552.
Completed iteration 225 with error 0.008956542454093608.
Completed iteration 250 with error 0.00507463627297966.
Completed iteration 275 with error 0.002875209574966675.
Completed iteration 300 with error 0.001629048808375444.
Completed iteration 325 with error 0.0009229935949193191.
Completed iteration 350 with error 0.0005229537457083211.
Completed iteration 375 with error 0.00029629741923287156.
Completed iteration 400 with error 0.00016787748700153315.
Completed iteration 425 with error 9.511676042706085e-05.
Completed iteration 450 with error 5.389166990710237e-05.
Completed iteration 475 with error 3.053417790255253e-05.
Completed iteration 500 with error 1.7300188005719974e-05.
Completed iteration 525 with error 9.802016151638782e-06.
Completed iteration 550 with error 5.55366914767319e-06.
Completed iteration 575 with error 3.1466221486198265e-06.
Completed iteration 600 with error 1.7828269136543895e-06.
Completed iteration 625 with error 1.0101218776981113e-06.
Terminated successfully in 627 iterations.
8 0.8888888888888888
Completed iteration 25 with error 0.8460605070496783.
Completed iteration 50 with error 0.4748541534684918.
Completed iteration 75 with error 0.2788181611011922.
Completed iteration 100 with error 0.16317372471699798.
Completed iteration 125 with error 0.09553448380320617.
Completed iteration 150 with error 0.05593656450190565.
Completed iteration 175 with error 0.03276931670900751.
Completed iteration 200 with error 0.01920113908680321.
Completed iteration 225 with error 0.01125091517433674.
Completed iteration 250 with error 0.006592479196839918.
Completed iteration 275 with error 0.00386286641577982.
Completed iteration 300 with error 0.0022634484706642866.
Completed iteration 325 with error 0.0013262687414226093.
Completed iteration 350 with error 0.0007771278194965703.
Completed iteration 375 with error 0.00045535842692601136.
Completed iteration 400 with error 0.0002668174935891443.
Completed iteration 425 with error 0.00015634184123314299.
Completed iteration 450 with error 9.16085785291898e-05.
Completed iteration 475 with error 5.367809152545533e-05.
Completed iteration 500 with error 3.1452704064349746e-05.
Completed iteration 525 with error 1.8429727369095872e-05.
Completed iteration 550 with error 1.0798907794651313e-05.
Completed iteration 575 with error 6.3276253214894496e-06.
Completed iteration 600 with error 3.707675148234557e-06.
Completed iteration 625 with error 2.1725140655348696e-06.
Completed iteration 650 with error 1.2729856990745247e-06.
Terminated successfully in 663 iterations.
9 1.0
Completed iteration 25 with error 0.8195566251536164.
Completed iteration 50 with error 0.46642498056927195.
Completed iteration 75 with error 0.28037678187634185.
Completed iteration 100 with error 0.16915170563319748.
Completed iteration 125 with error 0.10207516364071978.
Completed iteration 150 with error 0.061598680129037575.
Completed iteration 175 with error 0.03717262745708183.
Completed iteration 200 with error 0.02243236944053706.
Completed iteration 225 with error 0.01353714375674997.
Completed iteration 250 with error 0.008169188798902383.
Completed iteration 275 with error 0.004929817311051465.
Completed iteration 300 with error 0.0029749708714845724.
Completed iteration 325 with error 0.0017952899930691046.
Completed iteration 350 with error 0.0010833941905588063.
Completed iteration 375 with error 0.0006537901824543724.
Completed iteration 400 with error 0.0003945393158062416.
Completed iteration 425 with error 0.0002380905616092832.
Completed iteration 450 with error 0.00014367925643909985.
Completed iteration 475 with error 8.670536367105797e-05.
Completed iteration 500 with error 5.232362886431474e-05.
Completed iteration 525 with error 3.157546457543958e-05.
Completed iteration 550 with error 1.905467919982584e-05.
Completed iteration 575 with error 1.1498826843592269e-05.
Completed iteration 600 with error 6.9391364547755074e-06.
Completed iteration 625 with error 4.1875241052480305e-06.
Completed iteration 650 with error 2.5270231276408595e-06.
Completed iteration 675 with error 1.5249693490204663e-06.
Terminated successfully in 697 iterations.
Error in callback <function _draw_all_if_interactive at 0x7f2c85f09750> (for post_execute):
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/pyplot.py:120, in _draw_all_if_interactive()
118 def _draw_all_if_interactive():
119 if matplotlib.is_interactive():
--> 120 draw_all()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/_pylab_helpers.py:132, in Gcf.draw_all(cls, force)
130 for manager in cls.get_all_fig_managers():
131 if force or manager.canvas.figure.stale:
--> 132 manager.canvas.draw_idle()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2082, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
2080 if not self._is_idle_drawing:
2081 with self._idle_draw_cntx():
-> 2082 self.draw(*args, **kwargs)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:400, in FigureCanvasAgg.draw(self)
396 # Acquire a lock on the shared font cache.
397 with RendererAgg.lock, \
398 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
399 else nullcontext()):
--> 400 self.figure.draw(self.renderer)
401 # A GUI class may be need to update a window using this draw, so
402 # don't forget to call the superclass.
403 super().draw()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:255, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
254 try:
--> 255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'latex'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/formatters.py:340, in BaseFormatter.__call__(self, obj)
338 pass
339 else:
--> 340 return printer(obj)
341 # Finally look for special method names
342 method = get_real_method(obj, self.print_method)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/IPython/core/pylabtools.py:152, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
149 from matplotlib.backend_bases import FigureCanvasBase
150 FigureCanvasBase(fig)
--> 152 fig.canvas.print_figure(bytes_io, **kw)
153 data = bytes_io.getvalue()
154 if fmt == 'svg':
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:2342, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2336 renderer = _get_renderer(
2337 self.figure,
2338 functools.partial(
2339 print_method, orientation=orientation)
2340 )
2341 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2342 self.figure.draw(renderer)
2344 if bbox_inches:
2345 if bbox_inches == "tight":
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/figure.py:3140, in Figure.draw(self, renderer)
3137 # ValueError can occur when resizing a window.
3139 self.patch.draw(renderer)
-> 3140 mimage._draw_list_compositing_images(
3141 renderer, self, artists, self.suppressComposite)
3143 for sfig in self.subfigs:
3144 sfig.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axes/_base.py:3064, in _AxesBase.draw(self, renderer)
3061 if artists_rasterized:
3062 _draw_rasterized(self.figure, artists_rasterized, renderer)
-> 3064 mimage._draw_list_compositing_images(
3065 renderer, self, artists, self.figure.suppressComposite)
3067 renderer.close_group('axes')
3068 self.stale = False
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/image.py:131, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
129 if not_composite or not has_images:
130 for a in artists:
--> 131 a.draw(renderer)
132 else:
133 # Composite any adjacent images together
134 image_group = []
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1377, in Axis.draw(self, renderer, *args, **kwargs)
1374 renderer.open_group(__name__, gid=self.get_gid())
1376 ticks_to_draw = self._update_ticks()
-> 1377 tlb1, tlb2 = self._get_ticklabel_bboxes(ticks_to_draw, renderer)
1379 for tick in ticks_to_draw:
1380 tick.draw(renderer)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in Axis._get_ticklabel_bboxes(self, ticks, renderer)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/axis.py:1304, in <listcomp>(.0)
1302 if renderer is None:
1303 renderer = self.figure._get_renderer()
-> 1304 return ([tick.label1.get_window_extent(renderer)
1305 for tick in ticks if tick.label1.get_visible()],
1306 [tick.label2.get_window_extent(renderer)
1307 for tick in ticks if tick.label2.get_visible()])
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:959, in Text.get_window_extent(self, renderer, dpi)
954 raise RuntimeError(
955 "Cannot get window extent of text w/o renderer. You likely "
956 "want to call 'figure.draw_without_rendering()' first.")
958 with cbook._setattr_cm(self.figure, dpi=dpi):
--> 959 bbox, info, descent = self._get_layout(self._renderer)
960 x, y = self.get_unitless_position()
961 x, y = self.get_transform().transform((x, y))
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:378, in Text._get_layout(self, renderer)
375 ys = []
377 # Full vertical extent of font, including ascenders and descenders:
--> 378 _, lp_h, lp_d = _get_text_metrics_with_cache(
379 renderer, "lp", self._fontproperties,
380 ismath="TeX" if self.get_usetex() else False, dpi=self.figure.dpi)
381 min_dy = (lp_h - lp_d) * self._linespacing
383 for i, line in enumerate(lines):
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:97, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
94 """Call ``renderer.get_text_width_height_descent``, caching the results."""
95 # Cached based on a copy of fontprop so that later in-place mutations of
96 # the passed-in argument do not mess up the cache.
---> 97 return _get_text_metrics_with_cache_impl(
98 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/text.py:105, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
101 @functools.lru_cache(4096)
102 def _get_text_metrics_with_cache_impl(
103 renderer_ref, text, fontprop, ismath, dpi):
104 # dpi is unused, but participates in cache invalidation (via the renderer).
--> 105 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py:226, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
224 _api.check_in_list(["TeX", True, False], ismath=ismath)
225 if ismath == "TeX":
--> 226 return super().get_text_width_height_descent(s, prop, ismath)
228 if ismath:
229 ox, oy, width, height, descent, font_image = \
230 self.mathtext_parser.parse(s, self.dpi, prop)
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/backend_bases.py:645, in RendererBase.get_text_width_height_descent(self, s, prop, ismath)
641 fontsize = prop.get_size_in_points()
643 if ismath == 'TeX':
644 # todo: handle properties
--> 645 return self.get_texmanager().get_text_width_height_descent(
646 s, fontsize, renderer=self)
648 dpi = self.points_to_pixels(72)
649 if ismath:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:368, in TexManager.get_text_width_height_descent(cls, tex, fontsize, renderer)
366 if tex.strip() == '':
367 return 0, 0, 0
--> 368 dvifile = cls.make_dvi(tex, fontsize)
369 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1
370 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:300, in TexManager.make_dvi(cls, tex, fontsize)
298 with TemporaryDirectory(dir=cwd) as tmpdir:
299 tmppath = Path(tmpdir)
--> 300 cls._run_checked_subprocess(
301 ["latex", "-interaction=nonstopmode", "--halt-on-error",
302 f"--output-directory={tmppath.name}",
303 f"{texfile.name}"], tex, cwd=cwd)
304 (tmppath / Path(dvifile).name).replace(dvifile)
305 return dvifile
File /usr/share/miniconda3/envs/dse2023/lib/python3.10/site-packages/matplotlib/texmanager.py:259, in TexManager._run_checked_subprocess(cls, command, tex, cwd)
255 report = subprocess.check_output(
256 command, cwd=cwd if cwd is not None else cls.texcache,
257 stderr=subprocess.STDOUT)
258 except FileNotFoundError as exc:
--> 259 raise RuntimeError(
260 'Failed to process string with tex because {} could not be '
261 'found'.format(command[0])) from exc
262 except subprocess.CalledProcessError as exc:
263 raise RuntimeError(
264 '{prog} was not able to process the following string:\n'
265 '{tex!r}\n\n'
(...)
272 exc=exc.output.decode('utf-8', 'backslashreplace'))
273 ) from None
RuntimeError: Failed to process string with tex because latex could not be found
<Figure size 900x520 with 1 Axes>