<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>import pyChao</title><description>PY &amp; Chao&apos;s Murmurs</description><link>https://piyueh.github.io/</link><language>en</language><item><title>tikzposter and hyperref error</title><link>https://piyueh.github.io/posts/2025-08-27-tikzposter-and-hyperref-error/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2025-08-27-tikzposter-and-hyperref-error/</guid><pubDate>Thu, 28 Aug 2025 00:19:47 GMT</pubDate><content:encoded>&lt;p&gt;When you use the &lt;code&gt;tikzposter&lt;/code&gt; LaTeX class and also the &lt;code&gt;hyperref&lt;/code&gt; package with &lt;code&gt;colorlinks=true&lt;/code&gt;, and you encounter a compilation error similar to `! LaTeX Error:&lt;/p&gt;
&lt;p&gt;Loading a class or package in a group`, then the following snippet in your preamble may resolve the issue:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\makeatletter
\patchcmd{%
    \Hy@AtBeginDocumentHook%
}{%
    \RequirePackage {color}%
}{}{}{%
    \PackageWarning{patch}{patch failed!}%
}
\makeatother
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The core problem is that the &lt;code&gt;tikzposter&lt;/code&gt; class puts all of the main content inside one big &lt;code&gt;tikzpicture&lt;/code&gt; environment. More specifically, it starts a &lt;code&gt;\begin{tikzpicture}&lt;/code&gt; in &lt;code&gt;\AtBeginDocument&lt;/code&gt; but never closes it there.&lt;/p&gt;
&lt;p&gt;On the other hand , if &lt;code&gt;hyperref&lt;/code&gt; is configured with &lt;code&gt;colorlinks=true&lt;/code&gt;, it tries to load the &lt;code&gt;color&lt;/code&gt; package through its own &lt;code&gt;\AtBeginDocument&lt;/code&gt;, that package ends up being loaded &lt;em&gt;inside&lt;/em&gt; the still-open &lt;code&gt;tikzpicture&lt;/code&gt; environment. That’s what triggers the error about loading a class or package “in a group.”&lt;/p&gt;
&lt;p&gt;The fix we used basically prevents &lt;code&gt;hyperref&lt;/code&gt; from trying to load &lt;code&gt;color&lt;/code&gt; during its custom &lt;code&gt;\AtBeginDocument&lt;/code&gt; to resolve the conflict. The &lt;code&gt;color&lt;/code&gt; package is likely already loaded by other packages before &lt;code&gt;hyperref&lt;/code&gt;, so it&apos;s fine not loading it in &lt;code&gt;\AtBeginDocument&lt;/code&gt;.&lt;/p&gt;
</content:encoded></item><item><title>Listing files in each layer of an saved Docker image</title><link>https://piyueh.github.io/posts/2022-05-31-listing-files-in-each-layer-of-an-saved-docker-image/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2022-05-31-listing-files-in-each-layer-of-an-saved-docker-image/</guid><pubDate>Tue, 31 May 2022 21:01:08 GMT</pubDate><content:encoded>&lt;p&gt;If someone gives you a Docker image as a tarball, i.e., the output of &lt;code&gt;docker save&lt;/code&gt;, and if you want to find a file that was deleted at some point and does not exist in the final image, how to do it?&lt;/p&gt;
&lt;p&gt;Hint:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A Docker image is composed of layers (i.e., snapshots) of each Docker file command.&lt;/li&gt;
&lt;li&gt;Each layer in an image tarball is also itself a tarball.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A TLDR example solution (code can be found &lt;a href=&quot;https://gist.github.com/piyueh/3bafccf9d1d8435ac49454fa6ff1dc6e&quot;&gt;here&lt;/a&gt;):&lt;/p&gt;
&lt;p&gt;The code shown write a list of all files in each layer to user-specified text file. Then, we can check that text file to find the desired file. Finally, extract that single file from the tarball.&lt;/p&gt;
&lt;p&gt;Note, each layer was committed at the end of each Docker file command. So if the file was downloaded and removed in the same command, then there&apos;s no way to extract that file from the image history. For example, if the Docker file has something like:&lt;/p&gt;
&lt;p&gt;Then, the &lt;code&gt;abc.tar.gz&lt;/code&gt; will not be found in history.&lt;/p&gt;
</content:encoded></item><item><title>Removing unwanted space in LoF and LoT between chapters’ extries</title><link>https://piyueh.github.io/posts/2022-03-28-removing-unwanted-space-in-lof-and-lot-between-chapters-extries/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2022-03-28-removing-unwanted-space-in-lof-and-lot-between-chapters-extries/</guid><pubDate>Mon, 28 Mar 2022 20:20:56 GMT</pubDate><content:encoded>&lt;p&gt;In LaTeX, when using &lt;code&gt;book&lt;/code&gt; or &lt;code&gt;report&lt;/code&gt; class, there may be extra space in LoF (List of Figures) and LoT (List of Tables) that doesn&apos;t go away no matter how hard you try. The extra space is probably caused by the use of &lt;code&gt;\chapter&lt;/code&gt;. For example, consider the following dummy code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\documentclass[12pt]{report}
\usepackage{graphicx, titlesec, setspace, hyperref}

\singlespacing
\titlespacing{\chapter}{0pt}{0pt}{0pt}
\titleformat{\chapter}[hang]{\filcenter}{Chapter\ \thechapter}{0.5in}{}[]
\newcommand{\addfig}{\begin{figure}[h]\includegraphics{test.png}\caption{Test}\end{figure}}

\begin{document}
\listoffigures
\chapter{Chapter 1}\addfig\addfig
\chapter{Chapter 2}\addfig\addfig
\end{document}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The generated PDF (using &lt;code&gt;pdflatex&lt;/code&gt;) contains the following list of figures:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://pychao.com/wp-content/uploads/2022/03/20220328-143903EDT.png&quot; alt=&quot;&quot; /&gt; See the extra space between &lt;code&gt;List of Figures&lt;/code&gt; and the entry &lt;code&gt;1.1&lt;/code&gt; and also between the extry of &lt;code&gt;1.2&lt;/code&gt; and &lt;code&gt;2.1&lt;/code&gt;? Before you found this page, you probably already found some solutions that patch the command &lt;code&gt;\@chapter&lt;/code&gt;. For example, the best answer to this StackExchange question: &lt;a href=&quot;https://tex.stackexchange.com/a/121881&quot;&gt;https://tex.stackexchange.com/a/121881&lt;/a&gt; The explanations from those solutions are basically correct: the extra space is caused by that &lt;code&gt;\chapter&lt;/code&gt; calls an internal command &lt;code&gt;\@chapter&lt;/code&gt;, which adds the extra space to LoF through &lt;code&gt;\addtocontents{lof}{\protect\addvspace{10\p@}}&lt;/code&gt;. Assuming your TeX file is called &lt;code&gt;main.tex&lt;/code&gt;, then in the generated LoF file, &lt;code&gt;main.lof&lt;/code&gt;, you can see &lt;code&gt;\addvspace{10\p@}&lt;/code&gt; above the first entry of each chapter. &lt;strong&gt;&lt;em&gt;However&lt;/em&gt;&lt;/strong&gt;, the solution to patch &lt;code&gt;\@chapter&lt;/code&gt; does not work in many situations, for example, in the dummy TeX code we had above. Why? In our dummy code, the solution patching &lt;code&gt;\@chapter&lt;/code&gt; doesn&apos;t work because &lt;code&gt;\@chapter&lt;/code&gt; is overwritten by the package &lt;code&gt;hyperref&lt;/code&gt;. So the internal command that puts &lt;code&gt;\addvspace{10\p@}&lt;/code&gt; in LoF is not &lt;code&gt;\@chapter&lt;/code&gt; anymore. After loading &lt;code&gt;hyperref&lt;/code&gt;, the command responsible for adding the extra space is now &lt;code&gt;\Hy@org@chapter&lt;/code&gt;. That&apos;s the one we should patch. We can patch the command by adding the following code to the preamble:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\usepackage{etoolbox}
\makeatletter
\patchcmd{\Hy@org@chapter}{\addtocontents{lof}{\protect\addvspace{10\p@}}}{}{}{}
\makeatother
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, the generated LoF should look like &lt;img src=&quot;https://pychao.com/wp-content/uploads/2022/03/20220328-144004EDT.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;hyperref&lt;/code&gt; package is the commonly seen cause that renders the patching of &lt;code&gt;\@chapter&lt;/code&gt; failed. Sometimes even if you don&apos;t use &lt;code&gt;hyperref&lt;/code&gt; explicitly, some of your loaded packages actually load &lt;code&gt;hyperref&lt;/code&gt; silently. And that&apos;s why patching &lt;code&gt;\@chapter&lt;/code&gt; doesn&apos;t work even when you&apos;re not using &lt;code&gt;hyperref&lt;/code&gt;. In such a case, instead, patch the command &lt;code&gt;\Hy@org@chapter&lt;/code&gt;.&lt;/p&gt;
</content:encoded></item><item><title>Cotangent in NumPy: pathetic online Python tutorial</title><link>https://piyueh.github.io/posts/2021-10-19-cotangent-in-numpy-pathetic-online-python-tutorial/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2021-10-19-cotangent-in-numpy-pathetic-online-python-tutorial/</guid><pubDate>Tue, 19 Oct 2021 21:05:29 GMT</pubDate><content:encoded>&lt;p&gt;I never thought one day I would want to write a post regarding calculating &lt;a href=&quot;https://en.wikipedia.org/wiki/Trigonometric_functions#Right-angled_triangle_definitions&quot;&gt;cotangent&lt;/a&gt; with NumPy in Python. Isn&apos;t cotangent just the inverse of tangent? Can&apos;t we calculate cotangent just by one over tangent? Yes, cotangent is simple. It&apos;s probably mid-school math. However, if you&apos;ve ever searched &lt;code&gt;numpy cotangent&lt;/code&gt; on Google, you would be surprised that two of the top three search results (see the figure) are completely wrong. How pathetic! &lt;img src=&quot;https://pychao.com/wp-content/uploads/2021/10/Screenshot-2021-10-19-at-16-37-42-numpy-cotangent-Google-Search-1024x823.png&quot; alt=&quot;Search results of numpy cotangent&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Top three search results of &quot;numpy cotangent&quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;As you can see from the figure, the second and the third search result say you can use &lt;code&gt;arctan&lt;/code&gt; to calculate cotangent. Well... no! You definitely cannot use &lt;code&gt;arctan&lt;/code&gt; to calculate cotangent. &lt;code&gt;arctan&lt;/code&gt; is the inverse function of &lt;code&gt;tan&lt;/code&gt;, meaning if &lt;code&gt;y = tan(x)&lt;/code&gt;, then &lt;code&gt;x = arctan(y)&lt;/code&gt;, and it is totally different from cotangent. If you look further into other search results down the list, you will find more results showing this wrong information. This well explains how false information and fake news propagate on the internet. How pathetic! Here are some results showing wrong information, for your reference:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;https://python-tricks.com/mathematical-functions-in-numpy/#The_cosec_function_-_arcsin&lt;/li&gt;
&lt;li&gt;https://devenum.com/understanding-trigonometric-function-in-numpy/&lt;/li&gt;
&lt;li&gt;https://www.javatpoint.com/numpy-mathematical-functions&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item><item><title>Replacing XPS 13 7390 Cooling Fans with 9380/9370 Fans</title><link>https://piyueh.github.io/posts/2021-04-25-replacing-xps-13-7390-cooling-fans-with-9380-9370-fans/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2021-04-25-replacing-xps-13-7390-cooling-fans-with-9380-9370-fans/</guid><pubDate>Sun, 25 Apr 2021 05:44:48 GMT</pubDate><content:encoded>&lt;p&gt;About one year ago, my XPS 13 7390 started to make noise. The noise came from one of the fans. I managed to reduce the noise by tuning the cooling profile so that most of the time only the good fan was running, while the defective fan ran only when the temperature was high. (See the &lt;a href=&quot;https://pychao.com/2020/05/09/a-temporary-solution-to-rattling-fan-noise-of-dell-xps-13-7390-in-arch-linux/&quot;&gt;post I wrote at that time about how I tuned it in Arch Linux&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;Recently, the remaining good fan also started to make noise. I had relied on it too much to cool the machine over the past year, and that overuse wore it down. Two days ago, the noise became much worse and almost unbearable. It felt like it was going to explode.&lt;/p&gt;
&lt;p&gt;I had already ordered a replacement on eBay, but it had not arrived yet two days ago because it was an international shipment. So I had to come up with another solution.&lt;/p&gt;
&lt;p&gt;I tried using the fan from the previous version of the XPS 13. In the previous versions of the XPS 13, fans are separate parts and heat pipes are separate parts. In the XPS 13 7390, however, the fans and heat pipes are attached together as one assembly. So I was not sure it would work. It turned out that it did.&lt;/p&gt;
&lt;p&gt;And that is nice, because there are many more buying options for replacement fans from the previous version. You can order a 9380 (or 9370) fan replacement with Amazon Prime and get it the next day. That is exactly what I did.&lt;/p&gt;
&lt;p&gt;The picture below shows what I mean by saying that 9380 fans are just fans, while the 7390 uses a fan-heat-pipe assembly:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://pychao.com/wp-content/uploads/2021/04/PXL_20210425_021624757.MP_-225x300.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;On the left is the assembly from the XPS 13 7390, and on the right is the fan module from the 9380.&lt;/p&gt;
&lt;p&gt;The fans are actually composed of two parts: the rotor part and the shield. The rotor parts are the same whether they are from the 7390 or the 9380. Only the shields are different: the 7390 fan shield is welded to the heat pipes, while the 9380 fan shield is just a piece of metal.&lt;/p&gt;
&lt;p&gt;See the following picture:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://pychao.com/wp-content/uploads/2021/04/PXL_20210425_022155063.MP_-300x225.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;So I could just replace the rotor part. Awesome. I did that, and everything works like a charm now. It is so quiet.&lt;/p&gt;
&lt;p&gt;By the way, if anyone is interested in how dirty the old fans were, here&apos;s a picture:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://pychao.com/wp-content/uploads/2021/04/PXL_20210423_030512787.MP_-225x300.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;There was not a lot of dust, because I cleaned it once about one year ago, and I worked from home for the past year due to the pandemic. However, it does look like the dust affected the rotation of the rotors quite a bit. One of the rotors is cleaner. That one spun up less during the past year after I tuned the cooling profile.&lt;/p&gt;
</content:encoded></item><item><title>Sending desktop notification in Linux with Python with D-Bus directly</title><link>https://piyueh.github.io/posts/2021-03-01-sending-desktop-notification-in-linux-with-python-with-d-bus-directly/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2021-03-01-sending-desktop-notification-in-linux-with-python-with-d-bus-directly/</guid><pubDate>Tue, 02 Mar 2021 03:18:25 GMT</pubDate><content:encoded>&lt;p&gt;I recently found a lot of third-party libraries that help send desktop notifications in Linux. I just don&apos;t get it. Most of these libraries just wrap the call to &lt;code&gt;libnotify&lt;/code&gt;&apos;s &lt;code&gt;notify-send&lt;/code&gt; into a function or even an over-engineered class. You don&apos;t really need these third-party libraries to do the job... You can do the same job with merely two or three new lines in your code. &lt;code&gt;notify-send&lt;/code&gt; is a command-line tool. You can call the command-line tool through Python&apos;s &lt;code&gt;subprocess&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;Using &lt;code&gt;subprocess&lt;/code&gt; to call &lt;code&gt;notify-send&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import subprocess

subprocess.run(
    [&quot;notify-send&quot;, &quot;-u&quot;, &quot;normal&quot;, &quot;-t&quot;, &quot;3000&quot;,
     &quot;Hello world&quot;, &quot;This is the notification body.&quot;],
    check=True)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;notify-send&lt;/code&gt; is a quick solution but requires &lt;code&gt;libnotify&lt;/code&gt; and a call to an external executable. I don&apos;t like it. Therefore, I always send the notification directly with D-Bus&apos; Python binding. Most desktop notification servers follow a standard called &lt;a href=&quot;https://developer.gnome.org/notification-spec/&quot;&gt;Desktop Notifications Specification&lt;/a&gt;. It exposes a D-Bus interface at &lt;code&gt;org.freedesktop.Notifications&lt;/code&gt; and a method &lt;code&gt;org.freedesktop.Notifications.Notify&lt;/code&gt; to send notifications from users&apos; applications. It&apos;s OK if you don&apos;t know anything about D-Bus. Just remember that you can send a desktop notification through D-Bus&apos; Python binding:&lt;/p&gt;
&lt;p&gt;Sending a notification through D-Bus&apos; Python binding&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import dbus

item = &quot;org.freedesktop.Notifications&quot;

notfy_intf = dbus.Interface(
    dbus.SessionBus().get_object(item, &quot;/&quot;+item.replace(&quot;.&quot;, &quot;/&quot;)), item)

notfy_intf.Notify(
    &quot;&quot;, 0, &quot;&quot;, &quot;Hello world!&quot;, &quot;This is the notification body.&quot;,
    [], {&quot;urgency&quot;: 1}, 3000)

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The D-Bus&apos; Python binding can be installed from PyPI:&lt;/p&gt;
&lt;p&gt;Installing D-Bus&apos; Python binding&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ pip install dbus-python
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In &lt;code&gt;notfy_intf.Notify&lt;/code&gt;, the fourth argument is the notification title, and the content body is at the fifth argument. Regarding the urgency, &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, and &lt;code&gt;2&lt;/code&gt; mean &lt;code&gt;low&lt;/code&gt;, &lt;code&gt;normal&lt;/code&gt;, and &lt;code&gt;critical&lt;/code&gt;. The last argument indicates how long the notification box will be visible on the screen. The unit is milliseconds. So the &lt;code&gt;3000&lt;/code&gt; here means 3 seconds. To understand the details of the arguments in the &lt;code&gt;notfy_intf.Notify&lt;/code&gt;, refer to the documentation of &lt;a href=&quot;https://developer.gnome.org/notification-spec/#command-notify&quot;&gt;org.freedesktop.Notifications.Notify&lt;/a&gt;. You can now see that you don&apos;t really need those third-party libraries to send simple desktop notifications.&lt;/p&gt;
</content:encoded></item><item><title>Difference between PartOf and BindsTo in a systemd unit</title><link>https://piyueh.github.io/posts/2021-02-24-difference-between-partof-and-bindsto-in-a-systemd-unit/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2021-02-24-difference-between-partof-and-bindsto-in-a-systemd-unit/</guid><pubDate>Wed, 24 Feb 2021 08:55:12 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;Note: the Python script used to run all the tests mentioned in this post can be found on my GitHub Gist: &lt;a href=&quot;https://gist.github.com/piyueh/54b85e13800d42b9eccb47c7e0d6db7f&quot;&gt;https://gist.github.com/piyueh/54b85e13800d42b9eccb47c7e0d6db7f&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I&apos;ve been struggling for a while to understand the difference between &lt;code&gt;PartOf&lt;/code&gt; and &lt;code&gt;BindsTo&lt;/code&gt;. The man page for &lt;code&gt;systemd.unit&lt;/code&gt; says this about &lt;a href=&quot;https://www.freedesktop.org/software/systemd/man/systemd.unit.html#PartOf=&quot;&gt;PartOf=&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Configures dependencies similar to &lt;code&gt;Requires=&lt;/code&gt;, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency. Changes to this unit do not affect the listed units.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And for &lt;a href=&quot;https://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=&quot;&gt;&lt;code&gt;BindsTo=&lt;/code&gt;&lt;/a&gt;, it says:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Configures requirement dependencies, very similar in style to &lt;code&gt;Requires=&lt;/code&gt;. However, this dependency type is stronger: in addition to the effect of &lt;code&gt;Requires=&lt;/code&gt; it declares that if the unit bound to is stopped, this unit will be stopped too. This means a unit bound to another unit that suddenly enters inactive state will be stopped too. Units can suddenly, unexpectedly enter inactive state for different reasons: the main process of a service unit might terminate on its own choice, the backing device of a device unit might be unplugged or the mount point of a mount unit might be unmounted without involvement of the system and service manager.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;For reference, here&apos;s what the man page says about &lt;a href=&quot;https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Requires=&quot;&gt;&lt;code&gt;Requires=&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If this unit gets activated, the units listed will be activated as well. If one of the other units fails to activate, and an ordering dependency &lt;code&gt;After=&lt;/code&gt; on the failing unit is set, this unit will not be started. Besides, with or without specifying &lt;code&gt;After=&lt;/code&gt;, this unit will be stopped if one of the other units is explicitly stopped.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Maybe because I&apos;m not a native English speaker, the difference was not clear to me. So I decided to do some experiments.&lt;/p&gt;
&lt;h2&gt;Experiments&lt;/h2&gt;
&lt;p&gt;I carried out three groups of experiments. Each group corresponds to one of &lt;code&gt;Requires=&lt;/code&gt;, &lt;code&gt;PartOf=&lt;/code&gt;, and &lt;code&gt;BindsTo=&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In each group, a systemd unit &lt;code&gt;a.service&lt;/code&gt; was kept the same. It served as the dependency of the second systemd unit, &lt;code&gt;b.service&lt;/code&gt;. &lt;code&gt;b.service&lt;/code&gt; depended on &lt;code&gt;a.service&lt;/code&gt; using either &lt;code&gt;Requires=&lt;/code&gt;, &lt;code&gt;PartOf=&lt;/code&gt;, or &lt;code&gt;BindsTo=&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Eight tests were done for each group. In other words, I ran a total of 24 tests. To keep the experiments in user space, &lt;code&gt;a.service&lt;/code&gt; and &lt;code&gt;b.service&lt;/code&gt; were saved in &lt;code&gt;~/.config/systemd/user/&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here&apos;s the content of &lt;code&gt;a.service&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;a.service&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[Unit]
Description=Test service A

[Service]
Type=simple
ExecStart=sh -c &apos;while true; do echo A is alive; sleep 3; done&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following are the contents of &lt;code&gt;b.service&lt;/code&gt; in the three experiment groups:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Experiment group A: with &lt;code&gt;Requires=&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;b.service&lt;/code&gt; with &lt;code&gt;Requires=a.service&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;[Unit]
Description=Test service B.
Requires=a.service

[Service]
Type=simple
ExecStart=sh -c &apos;while true; do echo B is alive; sleep 3; done&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Experiment group B: with &lt;code&gt;PartOf=&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;b.service&lt;/code&gt; with &lt;code&gt;PartOf=a.service&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;[Unit]
Description=Test service B.
PartOf=a.service

[Service]
Type=simple
ExecStart=sh -c &apos;while true; do echo B is alive; sleep 3; done&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Experiment group C: with &lt;code&gt;BindsTo=&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;b.service&lt;/code&gt; with &lt;code&gt;BindsTo=a.service&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;[Unit]
Description=Test service B.
BindsTo=a.service

[Service]
Type=simple
ExecStart=sh -c &apos;while true; do echo B is alive; sleep 3; done&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following are the commands I ran in every experiment group, along with what I wanted to observe from the results:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Test 1 &lt;code&gt;    $ systemctl --user start a.service&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What I want to see&lt;/em&gt;: if &lt;code&gt;b.service&lt;/code&gt; also starts when &lt;code&gt;a.service&lt;/code&gt; starts.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test 2 &lt;code&gt;    $ systemctl --user start b.service&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What I want to see&lt;/em&gt;: if &lt;code&gt;a.service&lt;/code&gt; also starts when &lt;code&gt;b.service&lt;/code&gt; starts.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test 3 &lt;code&gt;    $ systemctl --user start a.service b.service  $ systemctl --user stop a.service&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What I want to see&lt;/em&gt;: if &lt;code&gt;b.service&lt;/code&gt; also stops when &lt;code&gt;a.service&lt;/code&gt; stops normally.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test 4 &lt;code&gt;    $ systemctl --user start a.service b.service  $ systemctl --user stop b.service&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What I want to see&lt;/em&gt;: if &lt;code&gt;a.service&lt;/code&gt; also stops when &lt;code&gt;b.service&lt;/code&gt; stops normally.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test 5 &lt;code&gt;    $ systemctl --user start a.service b.service  $ kill -9 $(systemctl --user show a.service | grep -oP &apos;(?&amp;lt;=ExecMainPID=)\d*&apos;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What I want to see&lt;/em&gt;: if &lt;code&gt;b.service&lt;/code&gt; stops when &lt;code&gt;a.service&lt;/code&gt; stops abnormally (i.e., &lt;code&gt;a.service&lt;/code&gt; is not stopped by &lt;code&gt;systemd&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test 6 &lt;code&gt;    $ systemctl --user start a.service b.service  $ kill -9 $(systemctl --user show b.service | grep -oP &apos;(?&amp;lt;=ExecMainPID=)\d*&apos;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What I want to see&lt;/em&gt;: if &lt;code&gt;a.service&lt;/code&gt; stops when &lt;code&gt;b.service&lt;/code&gt; stops abnormally (i.e., &lt;code&gt;b.service&lt;/code&gt; is not stopped by &lt;code&gt;systemd&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test 7 &lt;code&gt;    $ systemctl --user start a.service b.service  $ systemctl --user restart a.service&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What I want to see&lt;/em&gt;: if &lt;code&gt;b.service&lt;/code&gt; also restarts when &lt;code&gt;a.service&lt;/code&gt; restarts.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Test 8 &lt;code&gt;    $ systemctl --user start a.service b.service  $ systemctl --user restart b.service&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What I want to see&lt;/em&gt;: if &lt;code&gt;a.service&lt;/code&gt; also restarts when &lt;code&gt;b.service&lt;/code&gt; restarts.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Results&lt;/h2&gt;
&lt;p&gt;The following table shows the results. Each column represents an experiment group, and each row represents a test. Each result is either &lt;code&gt;V/V&lt;/code&gt;, &lt;code&gt;V/X&lt;/code&gt;, &lt;code&gt;X/V&lt;/code&gt;, or &lt;code&gt;X/X&lt;/code&gt;. They indicate whether &lt;code&gt;a.service&lt;/code&gt; and &lt;code&gt;b.service&lt;/code&gt; are running. For example, &lt;code&gt;V/X&lt;/code&gt; means &lt;code&gt;a.service&lt;/code&gt; is running while &lt;code&gt;b.service&lt;/code&gt; has stopped.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Requires&lt;/th&gt;
&lt;th&gt;PartOf&lt;/th&gt;
&lt;th&gt;BindsTo&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Test 1&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test 2&lt;/td&gt;
&lt;td&gt;V/V&lt;/td&gt;
&lt;td&gt;X/V&lt;/td&gt;
&lt;td&gt;V/V&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test 3&lt;/td&gt;
&lt;td&gt;X/X&lt;/td&gt;
&lt;td&gt;X/X&lt;/td&gt;
&lt;td&gt;X/X&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test 4&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test 5&lt;/td&gt;
&lt;td&gt;X/V&lt;/td&gt;
&lt;td&gt;X/V&lt;/td&gt;
&lt;td&gt;X/X&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test 6&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;td&gt;V/X&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test 7&lt;/td&gt;
&lt;td&gt;V/V&lt;/td&gt;
&lt;td&gt;V/V&lt;/td&gt;
&lt;td&gt;V/V&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test 8&lt;/td&gt;
&lt;td&gt;V/V&lt;/td&gt;
&lt;td&gt;V/V&lt;/td&gt;
&lt;td&gt;V/V&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;From the results, we can ignore the tests in which we applied changes to the status of &lt;code&gt;b.service&lt;/code&gt; (i.e., tests 4, 6, and 8), because changes to &lt;code&gt;b.service&lt;/code&gt; were not propagated to &lt;code&gt;a.service&lt;/code&gt;. This is expected behavior: &lt;code&gt;b.service&lt;/code&gt; depended on &lt;code&gt;a.service&lt;/code&gt;, but &lt;code&gt;a.service&lt;/code&gt; did not depend on &lt;code&gt;b.service&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;One exception is when we started &lt;code&gt;b.service&lt;/code&gt; (test 2). When we started &lt;code&gt;b.service&lt;/code&gt;, &lt;code&gt;a.service&lt;/code&gt; also started when using &lt;code&gt;Requires&lt;/code&gt; and &lt;code&gt;BindsTo&lt;/code&gt;. But when using &lt;code&gt;PartOf&lt;/code&gt;, starting &lt;code&gt;b.service&lt;/code&gt; had no effect on &lt;code&gt;a.service&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now let&apos;s look at what happened to &lt;code&gt;b.service&lt;/code&gt; when we changed the status of &lt;code&gt;a.service&lt;/code&gt; (i.e., tests 1, 3, 5, and 7). In test 1, starting &lt;code&gt;a.service&lt;/code&gt; did not trigger &lt;code&gt;b.service&lt;/code&gt; to start. This is expected, because &lt;code&gt;a.service&lt;/code&gt; did not know anything about &lt;code&gt;b.service&lt;/code&gt; before &lt;code&gt;b.service&lt;/code&gt; was loaded into &lt;code&gt;systemd&lt;/code&gt;. So when &lt;code&gt;a.service&lt;/code&gt; started, nothing happened to &lt;code&gt;b.service&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Once both &lt;code&gt;a.service&lt;/code&gt; and &lt;code&gt;b.service&lt;/code&gt; were running, &lt;code&gt;systemd&lt;/code&gt; knew about the existence of &lt;code&gt;b.service&lt;/code&gt; and the dependency relationship. In test 3, when both services were running and then we stopped &lt;code&gt;a.service&lt;/code&gt;, &lt;code&gt;b.service&lt;/code&gt; also stopped no matter whether the dependency was &lt;code&gt;Requires&lt;/code&gt;, &lt;code&gt;PartOf&lt;/code&gt;, or &lt;code&gt;BindsTo&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now comes the interesting part, at least to me. In test 5, we simulated a situation in which &lt;code&gt;a.service&lt;/code&gt; stopped unexpectedly. That is, &lt;code&gt;a.service&lt;/code&gt; was not stopped by &lt;code&gt;systemd&lt;/code&gt; or by any normal mechanism. It was killed with a &lt;code&gt;SIGKILL&lt;/code&gt; signal to mimic a crash. In that case, &lt;code&gt;b.service&lt;/code&gt; stopped only when using &lt;code&gt;BindsTo&lt;/code&gt;. In other words, when using &lt;code&gt;Requires&lt;/code&gt; and &lt;code&gt;PartOf&lt;/code&gt;, &lt;code&gt;b.service&lt;/code&gt; did not stop when &lt;code&gt;a.service&lt;/code&gt; crashed unexpectedly.&lt;/p&gt;
&lt;p&gt;Test 7 shows that when we restarted &lt;code&gt;a.service&lt;/code&gt;, &lt;code&gt;b.service&lt;/code&gt; also restarted regardless of whether the dependency was &lt;code&gt;Requires&lt;/code&gt;, &lt;code&gt;PartOf&lt;/code&gt;, or &lt;code&gt;BindsTo&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;h3&gt;&lt;code&gt;Requires&lt;/code&gt; v.s. &lt;code&gt;PartOf&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The difference is that when &lt;code&gt;b.service&lt;/code&gt; starts, &lt;code&gt;Requires=&lt;/code&gt; also starts &lt;code&gt;a.service&lt;/code&gt;. On the other hand, with &lt;code&gt;PartOf=&lt;/code&gt;, starting &lt;code&gt;b.service&lt;/code&gt; does not start &lt;code&gt;a.service&lt;/code&gt;. This is why the man page says &quot;&lt;em&gt;... similar to&lt;/em&gt; &lt;code&gt;Requires=&lt;/code&gt;&lt;em&gt;, but limited to stopping and restarting ...&lt;/em&gt;.&quot; Otherwise, &lt;code&gt;PartOf&lt;/code&gt; behaves the same as &lt;code&gt;Requires&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;code&gt;Requires&lt;/code&gt; v.s. &lt;code&gt;BindsTo&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;BindsTo&lt;/code&gt; differs from &lt;code&gt;Requires&lt;/code&gt; in test 5. When &lt;code&gt;a.service&lt;/code&gt; stopped accidentally or abnormally, &lt;code&gt;b.service&lt;/code&gt; stopped only when using &lt;code&gt;BindsTo&lt;/code&gt;. The man page does say that with &lt;code&gt;Requires&lt;/code&gt;, &quot;&lt;em&gt;explicitly&lt;/em&gt;&quot; stopping &lt;code&gt;a.service&lt;/code&gt; also stops &lt;code&gt;b.service&lt;/code&gt;. But it is less clear about the same situation when the stop is unexpected. The &lt;code&gt;BindsTo&lt;/code&gt; section explicitly says that unexpectedly stopping &lt;code&gt;a.service&lt;/code&gt; also stops &lt;code&gt;b.service&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;code&gt;PartOf&lt;/code&gt; v.s. &lt;code&gt;BindsTo&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;My main interest is the difference between &lt;code&gt;PartOf&lt;/code&gt; and &lt;code&gt;BindsTo&lt;/code&gt;. They differ in tests 2 and 5. So basically, the difference is:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Starting &lt;code&gt;b.service&lt;/code&gt; did not start &lt;code&gt;a.service&lt;/code&gt; when using &lt;code&gt;PartOf&lt;/code&gt;, but it did start &lt;code&gt;a.service&lt;/code&gt; when using &lt;code&gt;BindsTo&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;When &lt;code&gt;a.service&lt;/code&gt; stopped unexpectedly, using &lt;code&gt;BindsTo&lt;/code&gt; caused &lt;code&gt;b.service&lt;/code&gt; to stop as well. But using &lt;code&gt;PartOf&lt;/code&gt; did not.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;The last&lt;/h2&gt;
&lt;p&gt;Finally, one thing to remember is that these tests do not consider the situation where we &lt;code&gt;enable&lt;/code&gt; either service. If we use &lt;code&gt;enable&lt;/code&gt;, an extra &lt;code&gt;[Install]&lt;/code&gt; section is needed in the unit files. And in &lt;code&gt;[Install]&lt;/code&gt;, we have more options for configuring dependencies. Once we combine the dependency settings in &lt;code&gt;[Unit]&lt;/code&gt; and &lt;code&gt;[Install]&lt;/code&gt;, things may become more complicated.&lt;/p&gt;
</content:encoded></item><item><title>Using Google Chrome/Chromium with native Wayland backend in Arch Linux</title><link>https://piyueh.github.io/posts/2021-01-04-using-google-chrome-chromium-with-native-wayland-backend-in-arch-linux/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2021-01-04-using-google-chrome-chromium-with-native-wayland-backend-in-arch-linux/</guid><pubDate>Mon, 04 Jan 2021 16:02:51 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Updates&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Oct. 28, 2021: The bug mentioned in the Sep. 22 update has been fixed.&lt;/li&gt;
&lt;li&gt;Sep. 22, 2021: There was a bug affecting Wayland Chrome/Chromium/Electron in the latest Sway/wlroots (i.e., the latest git commit). See &lt;a href=&quot;https://github.com/swaywm/wlroots/issues/3168&quot;&gt;https://github.com/swaywm/wlroots/issues/3168&lt;/a&gt; and &lt;a href=&quot;https://bugs.chromium.org/p/chromium/issues/detail?id=1246834&quot;&gt;https://bugs.chromium.org/p/chromium/issues/detail?id=1246834&lt;/a&gt;. Before the bug was resolved, the workaround was to use the released versions of Sway/wlroots or just wait.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the past, we may need to use XWayland when using Google Chrome or Chromium under the Wayland environment. But now (as of 01/04/2021), it&apos;s possible to use native Wayland with Google Chrome/Chromium and even Electron-based apps if they are installed through the official repository or AUR. Just launch Google Chrome/Chromium with two additional flags:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;chromium --enable-features=UseOzonePlatform --ozone-platform=wayland
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It&apos;s the same for Electron-based apps:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;app executable&amp;gt; --enable-features=UseOzonePlatform --ozone-platform=wayland
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>Using biblatex with Elsevier’s cas-dc and cas-sc classes</title><link>https://piyueh.github.io/posts/2020-10-29-using-biblatex-with-elseviers-cas-dc-and-cas-sc-classes/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2020-10-29-using-biblatex-with-elseviers-cas-dc-and-cas-sc-classes/</guid><pubDate>Thu, 29 Oct 2020 20:49:00 GMT</pubDate><content:encoded>&lt;p&gt;In &lt;a href=&quot;https://www.ctan.org/pkg/els-cas-templates/&quot;&gt;els-cas-templates v2.1&lt;/a&gt;, the &lt;a href=&quot;https://support.stmdocs.in/wiki/index.php?title=Elsarticle_-_CAS&quot;&gt;documentation&lt;/a&gt; says that &lt;code&gt;biblatex&lt;/code&gt; plus &lt;code&gt;biber&lt;/code&gt; is recommended. However, if we actually try to use &lt;code&gt;biblatex&lt;/code&gt;, the compilation fails.&lt;/p&gt;
&lt;p&gt;This is because &lt;code&gt;cas-sc&lt;/code&gt; and &lt;code&gt;cas-dc&lt;/code&gt; use a length variable that is defined neither in &lt;code&gt;biblatex&lt;/code&gt; nor in &lt;code&gt;cas-sc&lt;/code&gt;/&lt;code&gt;cas-dc&lt;/code&gt;. That length variable is &lt;code&gt;bibsep&lt;/code&gt;. It is defined by &lt;code&gt;natbib&lt;/code&gt;, which is incompatible with &lt;code&gt;biblatex&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The solution is simple: just define &lt;code&gt;bibsep&lt;/code&gt; in the document preamble:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\makeatletter  
\newlength{\bibsep}{\@listi \global\bibsep\itemsep \global\advance\bibsep by\parsep}
\makeatother
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we should be able to discard &lt;code&gt;natbib&lt;/code&gt; and use &lt;code&gt;biblatex&lt;/code&gt;.&lt;/p&gt;
</content:encoded></item><item><title>Google Cloud Platform (GCP) is terrible for small-scale HPC purpose</title><link>https://piyueh.github.io/posts/2020-09-10-google-cloud-platform-gcp-is-terrible-for-small-scale-hpc-purpose/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2020-09-10-google-cloud-platform-gcp-is-terrible-for-small-scale-hpc-purpose/</guid><pubDate>Thu, 10 Sep 2020 08:58:37 GMT</pubDate><content:encoded>&lt;p&gt;I rarely use cloud-based HPC clusters for scientific simulations because they are just too expensive. I usually have access to clusters at different high-performance computing centers. But those clusters have one serious problem: too many people are waiting in the queue for resources. It&apos;s not uncommon for me to wait a day, or even several days, for my jobs to start after I submit them.&lt;/p&gt;
&lt;p&gt;For runs that take several days, waiting a day may be fine. But sometimes I just need a cluster for something like a 10-minute interactive session to debug internode parallel issues or run a quick benchmark. It makes no sense to wait one day just for a 10-minute job.&lt;/p&gt;
&lt;p&gt;So I decided to build my own personal HPC cluster with a cloud service provider. It sounded good. I could use a pay-as-you-go model. And because I would only use this cloud cluster for small jobs, it should not be too expensive.&lt;/p&gt;
&lt;p&gt;I had used Microsoft Azure at some point in the past. But after comparing prices and convenience, I decided to go with Google Cloud Platform.&lt;/p&gt;
&lt;p&gt;Everything went fine during the initial experimentation stage. I was able to build a small cluster with 10 compute nodes using very cheap instances, plus the Slurm scheduler and an NFS server. A Lustre cluster was too complicated, so I passed on that. Google Cloud Platform also doesn&apos;t seem to have InfiniBand. But that was okay for a personal cluster.&lt;/p&gt;
&lt;p&gt;However, terrible things happened when I moved into a more production-like stage. When I tried to replace those very cheap compute nodes with high-performance instances (i.e., C2-series instances) and GPUs, I started to regret using Google Cloud Platform.&lt;/p&gt;
&lt;p&gt;First, C2-series instances cannot have GPUs. This is ridiculous. Yes, I know machine learning applications usually don&apos;t need powerful CPUs. But I&apos;M NOT RUNNING MACHINE LEARNING APPLICATIONS. Many traditional scientific simulation programs exploit all available heterogeneous hardware. My applications need both powerful CPUs and GPUs.&lt;/p&gt;
&lt;p&gt;It is absurd that GPUs cannot be paired with powerful instances. It seems Google Cloud Platform only cares about machine learning applications. All of their web pages and promotions talk about machine learning. They don&apos;t seem to care about other applications that need more powerful machines.&lt;/p&gt;
&lt;p&gt;Second, they impose very restrictive quotas on how many CPUs and GPUs you can request. The default quota for C2 CPUs is 8 CPU cores, and the quota for V100 GPUs is 1 GPU. What kind of HPC cluster has only 8 CPU cores and 1 GPU?&lt;/p&gt;
&lt;p&gt;Okay, so I can request a quota increase. Fine. I submitted a request to increase the C2 CPU quota from 8 to 256 and the V100 GPU quota from 1 to 16. I thought that at least I could have a cluster with 8 nodes, each with 32 C2 cores and 2 V100 GPUs.&lt;/p&gt;
&lt;p&gt;But no. THEY REJECTED MY REQUEST IMMEDIATELY.&lt;/p&gt;
&lt;p&gt;I just don&apos;t understand. 256 CPU cores and 16 GPUs are not crazy numbers. And my cluster would not be running 24/7. It would only be up when I needed it. And the rejection came right after I clicked the request submission button. That means no real human had even reviewed my request. This is ridiculous. I&apos;m willing to pay out of my own pocket, but they do not even bother to review the request.&lt;/p&gt;
</content:encoded></item><item><title>WiFi works fine but gets significant packet loss</title><link>https://piyueh.github.io/posts/2020-09-04-wifi-works-fine-but-gets-significant-packet-loss/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2020-09-04-wifi-works-fine-but-gets-significant-packet-loss/</guid><pubDate>Fri, 04 Sep 2020 20:53:18 GMT</pubDate><content:encoded>&lt;p&gt;I had been having a packet loss issue with my XPS 13 7390 when connecting to my home 5GHz WiFi. The connection was fine. I could use the internet normally without any problem. But whenever I wanted to &lt;code&gt;ping&lt;/code&gt; something, the results always showed a lot of packet loss. Even when I &lt;code&gt;ping&lt;/code&gt; the machines in the same LAN, it was the same. The WiFi card of XPS 13 7390 is Intel Wi-Fi 6 AX200, and my router is NETGEAR Nighthawk AC1750. Turns out these have nothing to do with the packet loss issue. Not sure why, but I found (by trial-and-error) the power management/saving of the internet interface is the culprit (do not be confused with the WiFi card&apos;s power saving). There are several ways to disable power management. **Option 1:&lt;/p&gt;
&lt;p&gt;use &lt;code&gt;iw&lt;/code&gt; to disable power management of the interface** &lt;code&gt;iw&lt;/code&gt; can turn the power management of an interface off. Use this command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# iw &amp;lt;interface name&amp;gt; set power_save off
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can check if the power management is indeed turned off by &lt;code&gt;$ iw &amp;lt;interface name&amp;gt; get power_save&lt;/code&gt;
It should give you &lt;code&gt;off&lt;/code&gt;. And then do the pinging again to see if turning off the power management works. The above command only works temporarily. We&apos;ll have to re-run the command again next boot. To do this permanently, we can set a &lt;code&gt;udev&lt;/code&gt; rule as described in &lt;a href=&quot;https://wiki.archlinux.org/index.php/Power_management#Network_interfaces&quot;&gt;this Wiki post&lt;/a&gt; -- create a new file &lt;code&gt;/etc/udev/rules.d/81-wifi-powersave.rules&lt;/code&gt;, and add the following line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ACTION==&quot;add&quot;, SUBSYSTEM==&quot;net&quot;, KERNEL==&quot;wl*&quot;, RUN+=&quot;/usr/bin/iw dev $name set power_save on&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then reboot the machine. &lt;strong&gt;Option 2: use NetworkManager to disable power management for a specific network only&lt;/strong&gt; This option can do better control over when power management should be disabled based on the current network. For example, if we have the packet loss issue with a home 5GHz network but not with 2.4GHz. And we don&apos;t have the issue with our office&apos;s WiFi, either. So we may want to only disable the power management when connecting to the home 5GHz network. NetworkManager gives us this flexibility. To my knowledge, there&apos;s no way to set this parameter through the GUI of NetworkManager. So we have to go through a terminal. First, go to the setting interface of the target network:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ nmcli connection edit &amp;lt;network connection name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This should get us into an interactive interface with &lt;code&gt;nmcli&amp;gt;&lt;/code&gt; prompt. Go to the &lt;code&gt;802-11-wireless&lt;/code&gt; setting section:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nmcli&amp;gt; goto 802-11-wireless
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The prompt should change to &lt;code&gt;nmcli 802-11-wireless&amp;gt;&lt;/code&gt;. We can print out the current configuration in the &lt;code&gt;802-11-wireless&lt;/code&gt; section through &lt;code&gt;print&lt;/code&gt; command. We should see a line indicating the current setting of power management:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nmcli 802-11-wireless&amp;gt; print
---------------------------------------------------------
...
...
802-11-wireless.powersave: 0 (default)
...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A value of &lt;code&gt;0&lt;/code&gt; means, I guess (i.e., I&apos;m not sure), it will follow the global setting of NetworkManager, which may be &lt;code&gt;enable&lt;/code&gt;. Anyway, what we&apos;re going to do is to change this setting to &lt;code&gt;2&lt;/code&gt;, meaning &lt;code&gt;disable:&lt;/code&gt; &lt;code&gt;nmcli 802-11-wireless&amp;gt; set powersave 2&lt;/code&gt;
If we use &lt;code&gt;print&lt;/code&gt; to check the value, we should see ```
802-11-wireless.powersave:&lt;/p&gt;
&lt;p&gt;2 (disable)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; We can now save and quit by using ```
nmcli 802-11-wireless&amp;gt; save
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and &lt;code&gt;nmcli 802-11-wireless&amp;gt; quit&lt;/code&gt;
Finally, disconnect and reconnect the WiFi network to see if the issue is resolved.&lt;/p&gt;
</content:encoded></item><item><title>Regulatory domain warnings in system log</title><link>https://piyueh.github.io/posts/2020-09-04-regulatory-domain-warnings-in-system-log/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2020-09-04-regulatory-domain-warnings-in-system-log/</guid><pubDate>Fri, 04 Sep 2020 17:00:01 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Warning messages&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cfg80211: Loading compiled-in X.509 certificates for regulatory database
cfg80211: Loaded X.509 cert &apos;sforshee: 00b28ddf47aef9cea7&apos;
platform regulatory.0 Direct firmware load for regulatory.db failed with error -2
cfg80211: failed to load regulatory.db
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The explanation can be found here:
&lt;a href=&quot;https://wiki.archlinux.org/index.php/Network_configuration/Wireless#Respecting_the_regulatory_domain&quot;&gt;https://wiki.archlinux.org/index.php/Network_configuration/Wireless#Respecting_the_regulatory_domain&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Summary of steps to resolve the message&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install &lt;a href=&quot;https://www.archlinux.org/packages/?name=crda&quot;&gt;crda&lt;/a&gt; package&lt;/li&gt;
&lt;li&gt;Reboot to reload &lt;code&gt;cfg80211&lt;/code&gt; module&lt;/li&gt;
&lt;li&gt;&lt;code&gt;# iw reg set US&lt;/code&gt; (or any country code you want)&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item><item><title>Uninitialized urandom read</title><link>https://piyueh.github.io/posts/2020-09-03-uninitialized-urandom-read/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2020-09-03-uninitialized-urandom-read/</guid><pubDate>Fri, 04 Sep 2020 00:45:29 GMT</pubDate><content:encoded>&lt;p&gt;(Please correct me if my understanding is incorrect.) Today I checked the log of my system and noticed this line of warning.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;random: lvm: uninitialized urandom read
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After googling it, I learned &lt;code&gt;/dev/urandom&lt;/code&gt; is a pseudo-random number generator that is used by many programs. An introduction can be found in the man page of &lt;code&gt;urandom&lt;/code&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The random number generator gathers environmental noise from device drivers and other sources into an entropy pool. The generator also keeps an estimate of the number of bits of noise in the entropy pool. From this entropy pool random numbers are created.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Also, here&apos;s the reason (from my understanding) for the warning message:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A read from the /dev/urandom device will not block waiting for more entropy.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The system gathers random noises from hardware into an entropy pool for &lt;code&gt;urandom&lt;/code&gt; to use. That means if the system uptime is not long enough, there may not be enough entropy in the pool. So when &lt;code&gt;urandom&lt;/code&gt; requests data from the pool and when the pool is depleted, &lt;code&gt;urandom&lt;/code&gt; can not generate good random numbers and hence the warning message. In my case, this happened when &lt;code&gt;lvm&lt;/code&gt; requested a random number from &lt;code&gt;urandom&lt;/code&gt; during the booting time. Upon googling, there are three ways [1] to make sure there&apos;s enough entropy in the pool during the booting time (though I only tried the third one and resolved the warning):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use &lt;code&gt;systemd-boot&lt;/code&gt; as the boot manager, which initializes an entropy pool that can be used by programs during a booting period [2].&lt;/li&gt;
&lt;li&gt;Use some other pseudo-random number generators, such as &lt;code&gt;haveged&lt;/code&gt;[3], to increase the entropy in the pool.&lt;/li&gt;
&lt;li&gt;Use CPU&apos;s hardware random number generator (if the CPU has RDRAND [4] instruction) by setting the kernel parameter &lt;code&gt;random.trust\_cpu=on&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;[1] &lt;a href=&quot;https://bbs.archlinux.org/viewtopic.php?id=249430&quot;&gt;https://bbs.archlinux.org/viewtopic.php?id=249430&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[2] &lt;a href=&quot;https://systemd.io/RANDOM_SEEDS/&quot;&gt;https://systemd.io/RANDOM_SEEDS/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[3] &lt;a href=&quot;http://www.issihosts.com/haveged/&quot;&gt;http://www.issihosts.com/haveged/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[4] &lt;a href=&quot;https://en.wikipedia.org/wiki/RDRAND&quot;&gt;https://en.wikipedia.org/wiki/RDRAND&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item><item><title>Update on using ProtonMail Bridge on headless WordPress/Linux servers</title><link>https://piyueh.github.io/posts/2020-06-10-update-on-using-protonmail-bridge-on-headless-wordpress-linux-servers/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2020-06-10-update-on-using-protonmail-bridge-on-headless-wordpress-linux-servers/</guid><pubDate>Wed, 10 Jun 2020 19:01:41 GMT</pubDate><content:encoded>&lt;p&gt;Ever since I posted these two articles (&lt;a href=&quot;https://pychao.com/2018/10/13/use-protonmail-bridge-on-headless-linux-machines/&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://pychao.com/2018/10/14/use-protonmail-for-wordpress-servers-smtp-setting-on-google-cloud-platform/&quot;&gt;here&lt;/a&gt;) about using ProtonMail Bridge on a headless WordPress/Linux server, ProtonMail Bridge has changed quite a bit.&lt;/p&gt;
&lt;p&gt;It now has more support for non-graphical environments. For example, &lt;code&gt;gnome-keyring&lt;/code&gt; can be replaced with a command-line password manager called &lt;code&gt;pass&lt;/code&gt;. And ProtonMail Bridge now also has a &lt;code&gt;--noninteractive&lt;/code&gt; option so it can run without interaction.&lt;/p&gt;
&lt;p&gt;All this means that using ProtonMail Bridge on headless WordPress/Linux servers is now fairly easy. So I wrote this post to update how I currently use ProtonMail Bridge on my server.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;pass&lt;/code&gt; is friendlier to headless environments than &lt;code&gt;gnome-keyring&lt;/code&gt;. However, &lt;code&gt;pass&lt;/code&gt; requires a GPG key. And when using ProtonMail Bridge with &lt;code&gt;pass&lt;/code&gt; on a headless server, it is better to use a GPG key that does not require a passphrase.&lt;/p&gt;
&lt;p&gt;That is why I had been reluctant to write this update: there is a lot to cover. I am still reluctant to explain all the details, so I only include the commands needed to create a passphrase-free GPG key, set up &lt;code&gt;pass&lt;/code&gt;, and run ProtonMail Bridge in a headless environment using the updated approach.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Disclaimer: the practice described in this post is not safe. If the server is hacked, the ProtonMail credential may be easily obtained by hackers. So make sure the server is secure.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Prerequisites&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;pass -- most Linux distributions should have this in their official repositories&lt;/li&gt;
&lt;li&gt;GnuPG -- I guess most Linux distributions should already have this&lt;/li&gt;
&lt;li&gt;ProtonMail Bridge v1.2.7 -- I&apos;m not sure whether all distributions provide this package. If not, one option was to download the &lt;code&gt;.deb&lt;/code&gt; package for Debian-based distributions. Update: as of Sep. 07, 2021, v1.2.7 is no longer available. Please download the latest release from &lt;a href=&quot;https://protonmail.com/bridge/&quot;&gt;Bridge&apos;s official webpage&lt;/a&gt; or its &lt;a href=&quot;https://github.com/ProtonMail/proton-bridge/releases&quot;&gt;GitHub page&lt;/a&gt;. For Arch-based systems, there are several packages in AUR. Another option is to compile it from &lt;a href=&quot;https://github.com/ProtonMail/proton-bridge/releases&quot;&gt;the source code on GitHub&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Step 1: Create a passphrase-free GPG key non-interactively&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;$ gpg --batch --passphrase &apos;&apos; --quick-gen-key &apos;ProtonMail Bridge&apos; default default never
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The command above creates a basic GPG key, and its ID is &lt;em&gt;ProtonMail Bridge&lt;/em&gt;. This key does not have a passphrase, so &lt;code&gt;pass&lt;/code&gt; does not need to ask for one whenever it tries to use the key. The key does not expire.&lt;/p&gt;
&lt;p&gt;Do not use this key for other things, such as encryption, signing, or identity. It is not safe for those purposes. &lt;strong&gt;Note:&lt;/strong&gt; make sure the server has a firewall and is secure. If a hacker gets into the server, they can freely use this key to open the ProtonMail credential saved in &lt;code&gt;pass&lt;/code&gt;. &lt;strong&gt;So be careful.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;Step 2: set up &lt;code&gt;pass&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Initialize &lt;code&gt;pass&lt;/code&gt; with a key called &quot;ProtonMail Bridge&quot;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ pass init &quot;ProtonMail Bridge&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This creates a new password database in &lt;code&gt;pass&lt;/code&gt; (&lt;code&gt;pass&lt;/code&gt; calls the database a &lt;em&gt;password store&lt;/em&gt;). The GPG key &lt;em&gt;ProtonMail Bridge&lt;/em&gt; can then be used to open that database.&lt;/p&gt;
&lt;p&gt;If the server is multi-purpose, or even a machine for daily work, do not save other passwords or credentials in this database. Because of the passphrase-free GPG key, this database does not need a passphrase to open.&lt;/p&gt;
&lt;p&gt;After this step, we could continue using the old way of running ProtonMail Bridge in the background, as described &lt;a href=&quot;https://pychao.com/2018/10/14/use-protonmail-for-wordpress-servers-smtp-setting-on-google-cloud-platform/&quot;&gt;in this post&lt;/a&gt;. Alternatively, we can use the newer way described in the following steps.&lt;/p&gt;
&lt;h2&gt;Step 3: Start ProtonMail Bridge in command-line and interactive mode, then set it up&lt;/h2&gt;
&lt;p&gt;The new way to run ProtonMail Bridge in the background does not allow users to interact with the &lt;code&gt;protonmail-bridge&lt;/code&gt; daemon. We have to set up &lt;code&gt;protonmail-bridge&lt;/code&gt; interactively in advance. First, start &lt;code&gt;protonmail-bridge&lt;/code&gt; in command-line mode:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ protonmail-bridge --cli
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Log in to your ProtonMail account with the &lt;code&gt;login&lt;/code&gt; command and record the username and password of the local SMTP server. Please refer to &lt;a href=&quot;https://pychao.com/2018/10/14/use-protonmail-for-wordpress-servers-smtp-setting-on-google-cloud-platform/#step-1-set-up-bridge-through-the-command-line&quot;&gt;step 1 in the old post&lt;/a&gt; for details if you are not familiar with this. After setting up &lt;code&gt;protonmail-bridge&lt;/code&gt; and obtaining the required information (SMTP username and password), we can now use &lt;code&gt;exit&lt;/code&gt; to leave the interactive interface.&lt;/p&gt;
&lt;h2&gt;Step 4: Run ProtonMail Bridge in the background&lt;/h2&gt;
&lt;p&gt;This step is where it differs from the old way. Now we just execute the following two commands to start &lt;code&gt;protonmail-bridge&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ nohup protonmail-bridge --noninteractive &amp;gt; bridge_log.txt 2&amp;gt;&amp;amp;1 &amp;amp;
$ disown
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The commands above also redirect the output of &lt;code&gt;protonmail-bridge&lt;/code&gt; to a file called &lt;code&gt;bridge_log.txt&lt;/code&gt;. We can use &lt;code&gt;$ cat bridge_log.txt&lt;/code&gt; to read that output.&lt;/p&gt;
&lt;p&gt;One important thing is that the &lt;code&gt;protonmail-bridge&lt;/code&gt; daemon is now non-interactive, which means there is no way to send commands to the background daemon. If we want to control or change anything in &lt;code&gt;protonmail-bridge&lt;/code&gt;, we have to kill the daemon and then do the work through the interactive interface. This is a major drawback compared with the old method.&lt;/p&gt;
&lt;p&gt;For example, if &lt;code&gt;protonmail-bridge&lt;/code&gt; logs us out for some reason and requires us to sign in to the ProtonMail account again, in the old method we could just do &lt;code&gt;$ echo &quot;login&quot; &amp;gt; bridge_input &amp;amp;&amp;amp; echo &quot;*ProtonMail account*&quot; &amp;gt; bridge_input &amp;amp;&amp;amp; echo &quot;*ProtonMail password*&quot; &amp;gt; bridge_input&lt;/code&gt; to log in again. With the &lt;code&gt;--noninteractive&lt;/code&gt; method, however, we have to kill the &lt;code&gt;protonmail-bridge&lt;/code&gt; daemon, start &lt;code&gt;$ protonmail-bridge --cli&lt;/code&gt;, log in, exit, and then start the background daemon again.&lt;/p&gt;
&lt;p&gt;Another example is checking the status of the daemon. In the old method, we could just do &lt;code&gt;$ echo &quot;info&quot; &amp;gt; bridge_input &amp;amp;&amp;amp; cat bridge_output&lt;/code&gt; to see whether the daemon was still working. With the &lt;code&gt;--noninteractive&lt;/code&gt; method, we cannot issue the &lt;code&gt;info&lt;/code&gt; command to the daemon.&lt;/p&gt;
&lt;p&gt;Finally, we can continue with &lt;a href=&quot;https://pychao.com/2018/10/14/use-protonmail-for-wordpress-servers-smtp-setting-on-google-cloud-platform#step-3-test-if-bridge-in-the-background-is-working&quot;&gt;step 3&lt;/a&gt; and &lt;a href=&quot;https://pychao.com/2018/10/14/use-protonmail-for-wordpress-servers-smtp-setting-on-google-cloud-platform#step-4-set-up-smtp-server-information-in-wordpress&quot;&gt;step 4 in the old post&lt;/a&gt; to set up the WP Mail SMTP plugin as usual.&lt;/p&gt;
&lt;h2&gt;Also... to reduce GUI-related dependencies&lt;/h2&gt;
&lt;p&gt;For those who don&apos;t like to install a lot of GUI-related dependencies on a server, we can compile and build &lt;code&gt;protonmail-bridge&lt;/code&gt; from &lt;a href=&quot;https://github.com/ProtonMail/proton-bridge&quot;&gt;the source code on GitHub&lt;/a&gt;. Just build the &lt;code&gt;build-nogui&lt;/code&gt; target with &lt;code&gt;make&lt;/code&gt;. See the &lt;a href=&quot;https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=protonmail-bridge-nogui&quot;&gt;PKGBUILD of this AUR package&lt;/a&gt;.&lt;/p&gt;
</content:encoded></item><item><title>A temporary solution to rattling fan noise of Dell XPS 13 7390 in Arch Linux</title><link>https://piyueh.github.io/posts/2020-05-09-a-temporary-solution-to-rattling-fan-noise-of-dell-xps-13-7390-in-arch-linux/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2020-05-09-a-temporary-solution-to-rattling-fan-noise-of-dell-xps-13-7390-in-arch-linux/</guid><pubDate>Sat, 09 May 2020 04:11:51 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;To be clear&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;This is for Arch Linux. No idea about Windows.&lt;/li&gt;
&lt;li&gt;It only works if the noise comes from a loosened or shaking fan.&lt;/li&gt;
&lt;li&gt;It works when only one fan has this problem. If both fans are making the same noise, it&apos;s hopeless. Just get a replacement.&lt;/li&gt;
&lt;li&gt;It&apos;s a &lt;strong&gt;&lt;em&gt;temporary&lt;/em&gt;&lt;/strong&gt; solution. And the system temperature will be higher than usual because we&apos;ll lose some cooling capability.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; See point 4 above. If you follow my solution and the CPU is eventually burnt down, I&apos;m not going to be responsible for that.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Updates:&lt;/strong&gt; I finally replaced the fan. See &lt;a href=&quot;https://pychao.com/2021/04/25/replacing-xps-13-7390-cooling-fans-with-9380-9370-fans/&quot;&gt;this blog&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;Just murmuring...&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;The pandemic is giving most people a hard time, including me, which is surprising to me. I used to work from home a lot. After all, I only need stable internet to work, and I&apos;m a perfect homebody. So I never thought I would one day be unhappy about working from home for an extended period.&lt;/p&gt;
&lt;p&gt;My unhappiness comes from my newly purchased XPS 13 7390. It started making a very annoying noise. That noise really drove me crazy before I fixed it. And this is a new laptop. So even though the noise is now gone, I&apos;m still kind of sad that I had to open the back panel when it is just 5 months old. I think opening the back panel voids the warranty.&lt;/p&gt;
&lt;p&gt;XPS 13 7390 is a fantastic machine, except for the fan quality. Though it might also be because I attached this XPS 13 to a 27&quot; 4K monitor and never shut it down since mid-March. The fan axle, or somewhere around it, had worn down. I guess an ultrabook is not supposed to be used as a desktop. A bit disappointing.&lt;/p&gt;
&lt;p&gt;My other laptop (Lenovo W540) has been up and running as a server since 2014 without a single problem. (I had to replace the thermal paste last year, but that counts as maintenance.)&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;I. Symptom&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;Rattling noise coming from the fans. Note that the fans also create an airflow noise. The airflow noise is normal and is fine. Here&apos;s a video showing the rattling noise. Not sure if headphones are required to hear that.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/fclAuJWgcEo&quot;&gt;https://youtu.be/fclAuJWgcEo&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;II. Diagnosis&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;After removing the back panel, we can check the condition of the fans. In the following video, we can see one fan making a &quot;click click click&quot; sound when I tap it, while the other one does not. (You may need headphones/earphones to hear the sound.) This is the one making the rattling noise.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://youtu.be/6is85RMe1m4&quot;&gt;https://youtu.be/6is85RMe1m4&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I&apos;m not sure what really happened to this fan. But I&apos;ll just call it a loosened fan because it sounds like something is loose. I have to admit I&apos;m kind of disappointed in Dell&apos;s quality control. The greatness of the XPS 13 is undermined by this little plastic fan.&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;III. A permanent solution&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;The fan should be replaced. The part number can be found on the surface of the cooling assembly. Unfortunately, I couldn&apos;t find a replacement in the market. (Well, I did find two sellers on eBay. But the shipments would take more than 40 days.)&lt;/p&gt;
&lt;p&gt;My XPS 13 7390 uses a combined fan-heatpipe assembly. In other words, the fan module and the heatpipe cannot be detached from each other. But currently, most available cooling modules on the market are for previous generations, such as 9380 and 9370. These earlier generations use separate fans and heatpipes. I&apos;m not sure whether those fan and heatpipe modules can replace the fan-heatpipe assembly in my XPS 13. The pictures look alike, though. I just haven&apos;t tried them yet, and I haven&apos;t purchased them either.&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;IV. A temporary solution&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;A temporary solution is to delay the point at which the loosened fan kicks in. By default, both fans have the same speed profile. But we can actually control them separately in Linux.&lt;/p&gt;
&lt;p&gt;The basic idea is to rely on the normal fan to cool the system for most temperature ranges. The loosened fan only kicks in when the temperature is close to a critical value. This will, of course, keep the system at a higher temperature than usual. But the CPU is designed to tolerate temperatures up to 100ºC (supposedly...). So it should be fine, hopefully, to let it stay at something like 50ºC when idle or under light workloads.&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Step 1: &lt;em&gt;i8kutils-git&lt;/em&gt;&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;i8kutils&lt;/em&gt; provides utilities to monitor and control the fans in Dell laptops. The &lt;em&gt;i8kutils&lt;/em&gt; package in AUR, however, has outdated code and is buggy (for example, it doesn&apos;t handle more than 4 stages). So here we need to use the version on GitHub. Fortunately, &lt;a href=&quot;https://aur.archlinux.org/packages/i8kutils-git/&quot;&gt;&lt;em&gt;i8kutils&lt;/em&gt;-git&lt;/a&gt; can also be found in AUR.&lt;/p&gt;
&lt;p&gt;The package provides a kernel module, &lt;code&gt;dell_smm_hwmon&lt;/code&gt;. This module has trouble being loaded for recent generations of XPS. To force the kernel to automatically load &lt;code&gt;dell_smm_hwmon&lt;/code&gt; during startup, we have to add an option &lt;code&gt;ignore_dmi=1&lt;/code&gt;. Here&apos;s what I have in &lt;code&gt;/etc/modprobe.d/dell-smm-hwmon.conf&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;Content in /etc/modprobe.d/dell-smm-hwmon&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ cat /etc/modprobe.d/dell-smm-hwmon.conf
-----------------------------------------------------------------------
# This file must be at /etc/modprobe.d/
options dell-smm-hwmon restricted=0 ignore_dmi=1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or, if you want to manually load the module without rebooting, use &lt;code&gt;# modprobe dell_smm_hwmon ignore_dmi=1&lt;/code&gt;. For loading and checking the status of kernel modules, please see &lt;a href=&quot;https://wiki.archlinux.org/index.php/Kernel_module&quot;&gt;the article on kernel modules in ArchWiki&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Next, enable the &lt;code&gt;i8kmon&lt;/code&gt; daemon with &lt;code&gt;# systemctl enable i8kmon.service&lt;/code&gt;. If you don&apos;t want to reboot later, you also need to start the daemon. &lt;code&gt;i8kmon&lt;/code&gt; is a daemon provided by &lt;em&gt;i8kutils&lt;/em&gt; to monitor temperatures and then adjust fan speeds according to the configured profiles. We haven&apos;t configured the fan profile yet, so &lt;code&gt;i8kmon&lt;/code&gt; is not ready to work. We need to wait until the next step is done. &lt;em&gt;i8kutils&lt;/em&gt; also provides &lt;code&gt;i8kctl&lt;/code&gt; and &lt;code&gt;i8kfan&lt;/code&gt; to manually control the fans, but they will also only work after the next step is done.&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Step 2: &lt;em&gt;dell-bios-fan-control-git&lt;/em&gt;&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The package &lt;a href=&quot;https://aur.archlinux.org/packages/dell-bios-fan-control-git/&quot;&gt;&lt;em&gt;dell-bios-fan-control-git&lt;/em&gt;&lt;/a&gt; provides a tool called &lt;code&gt;dell-bios-fan-control&lt;/code&gt; and can be found in AUR. For recent XPS 13 models, the fans are controlled by the BIOS by default. So in order for &lt;code&gt;i8kmon&lt;/code&gt; to control the fans, we need to transfer that control from the BIOS to ourselves. This is what &lt;code&gt;dell-bios-fan-control&lt;/code&gt; does. After installing &lt;em&gt;dell-bios-fan-control-git&lt;/em&gt;, enable the daemon with &lt;code&gt;# systemctl enable dell-bios-fan-control.service&lt;/code&gt;. And if you don&apos;t want to reboot, start the daemon too.&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Step 3: testing if manual control is working&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;We haven&apos;t configured the profiles yet. Before that, we may want to see if the two packages above are working. Let&apos;s try to control the fan manually. Follow the instructions in &lt;a href=&quot;https://wiki.archlinux.org/index.php/Lm_sensors&quot;&gt;&lt;em&gt;lm_sensors&lt;/em&gt;&apos; wiki page&lt;/a&gt;, and check whether you can see the current fan speeds in the output of the &lt;code&gt;sensors&lt;/code&gt; command. Here&apos;s an example showing the speeds of the two fans in my XPS 13 7390:&lt;/p&gt;
&lt;p&gt;Report from lm_sensors&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ sensors
------------------------------------------------------------------------
coretemp-isa-0000
Adapter: ISA adapter
Package id 0:  +75.0°C  (high = +100.0°C, crit = +100.0°C)
Core 0:        +71.0°C  (high = +100.0°C, crit = +100.0°C)
Core 1:        +70.0°C  (high = +100.0°C, crit = +100.0°C)
Core 2:        +70.0°C  (high = +100.0°C, crit = +100.0°C)
Core 3:        +72.0°C  (high = +100.0°C, crit = +100.0°C)
Core 4:        +75.0°C  (high = +100.0°C, crit = +100.0°C)
Core 5:        +69.0°C  (high = +100.0°C, crit = +100.0°C)

nvme-pci-7100
Adapter: PCI adapter
Composite:    +44.9°C  (low  =  -0.1°C, high = +81.8°C)
                       (crit = +85.8°C)

iwlwifi_1-virtual-0
Adapter: Virtual device
temp1:        +49.0°C  

BAT0-acpi-0
Adapter: ACPI interface
in0:           8.51 V  
curr1:            N/A  

dell_smm-virtual-0
Adapter: Virtual device
fan1:        7349 RPM
fan2: 7072 RPM

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you haven&apos;t rebooted yet, or if you haven&apos;t loaded/started the kernel module and systemd services, you may want to do so now. Next, use &lt;code&gt;i8kfan&lt;/code&gt; to change the fan speeds and see whether it is working.&lt;/p&gt;
&lt;p&gt;In fact, we are not controlling the real speeds of the fans directly. We are controlling the modes. These fans have three modes: 0, 1, and 2. Mode 0 means no motion, i.e., 0 RPM. Mode 1 makes the fans rotate at around 4500 RPM. Mode 2 makes the fans rotate at the highest speed, around 7500 RPM. The usage of &lt;code&gt;i8kfan&lt;/code&gt; is &lt;code&gt;$ i8kfan &amp;lt;mode for fan 1&amp;gt; &amp;lt;mode for fan 2&amp;gt;&lt;/code&gt;. For example, &lt;code&gt;$ i8kfan 2 2&lt;/code&gt; makes both fans rotate at around 7500 RPM.&lt;/p&gt;
&lt;p&gt;You can check the speeds again with the &lt;code&gt;sensors&lt;/code&gt; command. Another command to check the speeds is &lt;code&gt;i8kctl&lt;/code&gt;. Now try different mode combinations for the two fans and identify which fan is making the rattling noise. In my case, &lt;code&gt;fan1&lt;/code&gt; is the one. Note that the fan id (&lt;code&gt;fan1&lt;/code&gt; or &lt;code&gt;fan2&lt;/code&gt;) may be different between &lt;em&gt;lm_sensors&lt;/em&gt; and &lt;em&gt;i8kutils&lt;/em&gt;. So you need to use &lt;code&gt;i8kfan&lt;/code&gt; to determine which id is the rattling fan in &lt;code&gt;i8kutils&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Step 4: setting up the fan speed profile&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Now we can set up the profile. The fan profile can be set in either &lt;code&gt;/etc/i8kutils/i8kmon.conf&lt;/code&gt; or &lt;code&gt;${HOME}/.i8kmon&lt;/code&gt;. But by default, the &lt;code&gt;i8kmon.service&lt;/code&gt; shipped with the Arch Linux package ignores &lt;code&gt;${HOME}/.i8kmon&lt;/code&gt;. So if you want to use &lt;code&gt;${HOME}/.i8kmon&lt;/code&gt;, you&apos;ll have to create your own systemd service. Let&apos;s just use &lt;code&gt;/etc/i8kutils/i8kmon.conf&lt;/code&gt;. Here&apos;s what I have:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cat /etc/i8kutils/i8kmon.conf
------------------------------------------------------------------------
# i8kmon configuration file for Dell XPS 13 7390 with one fan rattling
# Requires the version on GitHub. In Arch, install i8kutils-git

# External program to control the fans
set config(i8kfan)	/usr/bin/i8kfan

# Report status on stdout, override with --verbose option
set config(verbose) 0

# Status check timeout (seconds), override with --timeout option
set config(timeout) 1

# Temperature threshold at which the temperature is displayed in red
set config(t_high) 90

# Number of temperature configurations
set config(num_configs)  5

# Temperature thresholds: {fan_speeds low_ac high_ac low_batt high_batt}
set config(0)   {{0 0}  -1  40  -1  40}
set config(1)   {{0 1}  35  55  35  55}
set config(2)   {{0 2}  50  75  50  75}
set config(3)   {{1 2}  70  80  70  80}
set config(4)   {{2 2}  75  128  75  128}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;set config(num_configs) 5&lt;/code&gt; means we have 5 stages in our speed profile. The most important part is the lines with the following pattern: &lt;code&gt;set config(&amp;lt;stage_id&amp;gt;) {{&amp;lt;fan1_mode&amp;gt; &amp;lt;fan2_mode&amp;gt;} &amp;lt;low_temp_ac&amp;gt; &amp;lt;high_temp_ac&amp;gt; &amp;lt;low_temp_bat&amp;gt; &amp;lt;high_temp_bat&amp;gt;}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;stage_id&amp;gt;&lt;/code&gt; speaks for itself. &lt;code&gt;&amp;lt;fan1_mode&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;fan2_mode&amp;gt;&lt;/code&gt; are the fan modes (0, 1, or 2) at this stage. &lt;code&gt;&amp;lt;low_temp_ac&amp;gt;&lt;/code&gt; means that when:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;we&apos;re using AC power, and&lt;/li&gt;
&lt;li&gt;the temperature is decreasing,&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;once the temperature reaches this value, the fans will go back to the previous stage (the stage with the &lt;code&gt;&amp;lt;stage_id&amp;gt;&lt;/code&gt; that is one smaller). &lt;code&gt;&amp;lt;low_temp_bat&amp;gt;&lt;/code&gt; is the same except it applies when using battery power. &lt;code&gt;&amp;lt;high_temp_ac&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;high_temp_bat&amp;gt;&lt;/code&gt;, on the other hand, mean that when the temperature is increasing, the fan speed will move to the next stage when reaching that temperature value.&lt;/p&gt;
&lt;p&gt;In my profile, I don&apos;t use different profiles for AC power and battery power. My profile says that when the temperature is increasing:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;at 40 ºC, fan2 kicks in but with medium speed;&lt;/li&gt;
&lt;li&gt;at 55 ºC, fan2 starts to rotate at the highest speed, but fan1 is still unmoving;&lt;/li&gt;
&lt;li&gt;at 75 ºC, fan1 finally starts to work, though with medium speed (while fan2 still running at the highest speed); and&lt;/li&gt;
&lt;li&gt;at 80 ºC, fan1 starts to rotate at the highest speed.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When the temperature is decreasing:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;at 75ºC, fan1 lowers the speed to the medium speed;&lt;/li&gt;
&lt;li&gt;at 70ºC, fan1 stops working, and only fan2 continues to work;&lt;/li&gt;
&lt;li&gt;at 50ºC, fan2 slows down; and&lt;/li&gt;
&lt;li&gt;at 35ºC, fan2 also stops working.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;With this profile, if the laptop is not under a heavy workload, then most of the time only the normal fan is working. The rattling fan only starts working when the temperature is high. After setting up the profile, remember to restart the &lt;code&gt;i8kmon.service&lt;/code&gt; daemon, or simply reboot.&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Step 5: relax the CPU frequency restriction at high temperature:&lt;/strong&gt; &lt;em&gt;throttled&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;The last step is recommended but not required.&lt;/p&gt;
&lt;p&gt;The CPU is designed to withstand temperatures up to 100ºC. But if we allow the CPU to reach 100ºC, the machine will automatically shut down for protection, and we will lose all data before the shutdown. The Linux kernel therefore reduces a CPU core&apos;s frequency at around 80ºC, so that the machine never really reaches 100ºC.&lt;/p&gt;
&lt;p&gt;But now, because we are using only one fan most of the time, the temperature is usually high. For example, in my case, the temperature is usually around 70ºC when watching YouTube and doing a video call at the same time. It&apos;s easy to reach 80ºC if I&apos;m also doing something else in that situation. The Linux kernel would start to limit the CPU frequencies soon because of the 80ºC threshold.&lt;/p&gt;
&lt;p&gt;To change this threshold temperature, we need to install &lt;em&gt;throttled&lt;/em&gt;. &lt;em&gt;throttled&lt;/em&gt; can be found in the official Arch Linux repository. After installation, enable &lt;code&gt;lenovo_fix.service&lt;/code&gt; with &lt;code&gt;# systemctl enable lenovo_fix.service&lt;/code&gt;. If you don&apos;t want to reboot, don&apos;t forget to start the daemon too. And I don&apos;t know why the service is named Lenovo.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;throttled&lt;/em&gt;&apos;s default configuration changes the 80ºC threshold to 95ºC. This means the Linux kernel should not limit the CPU frequency until reaching 95ºC. So now, even though my machine may stay around 70-ish ºC and sometimes spike to 80-ish ºC, the CPU can still run at a normal frequency. If you don&apos;t like 95ºC and want another threshold value, you&apos;ll have to check &lt;em&gt;throttled&lt;/em&gt;&apos;s manual.&lt;/p&gt;
&lt;h2&gt;&lt;strong&gt;V. Finally ...&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;The best solution is still to get a brand new replacement, of course. If anyone reads this post and knows where to get one, please tell me. Thanks.&lt;/p&gt;
</content:encoded></item><item><title>Murmur: should we use swap space?</title><link>https://piyueh.github.io/posts/2020-01-08-murmur-should-we-use-swap-space/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2020-01-08-murmur-should-we-use-swap-space/</guid><pubDate>Wed, 08 Jan 2020 19:51:58 GMT</pubDate><content:encoded>&lt;p&gt;I recently read &lt;a href=&quot;https://www.reddit.com/r/linuxquestions/comments/8h1t1i/can_intel_optane_ssds_be_used_as_linux_swap_space/&quot;&gt;a Reddit post&lt;/a&gt; asking whether an Intel Optane SSD can be used for swap space in Linux. I didn&apos;t really care about the question itself or the answer. I was just waiting for my bus at a bus stop and browsing random posts online.&lt;/p&gt;
&lt;p&gt;However, when I read the replies, I found that I couldn&apos;t agree with one of them. The OP was planning to build a machine for a Minecraft server. They would get 32 GB of RAM and were wondering whether swap was needed and whether Intel Optane could be used as swap. I don&apos;t know if 32 GB of RAM is enough for a Minecraft server. But one guy said 32 GB of RAM was enough, so swap was not needed unless the OP planned to do scientific computing or video editing.&lt;/p&gt;
&lt;p&gt;In other words, this guy thought swap might be necessary if the machine were going to run scientific computing workloads. That&apos;s when I felt like I had to say something.&lt;/p&gt;
&lt;p&gt;My opinion: for scientific computing, swap should not be used.&lt;/p&gt;
&lt;p&gt;A good scientific computing program should crash when OOM (out-of-memory) happens. Then users know OOM occurred and realize they have to deal with the issue. If swap is used, a scientific computing program that hits OOM may keep running without the user&apos;s notice. And the computing performance goes down because of the I/O to swap.&lt;/p&gt;
&lt;p&gt;This is unacceptable because for long-running scientific calculations, time is money. Especially when the program runs on cloud VMs or a non-free cluster, every CPU-hour credit is precious. That is also why a good scientific computing program should have a checkpoint mechanism. Then we can always restart the calculation from the point before the crash.&lt;/p&gt;
&lt;p&gt;As for the general use case of swap, I can only speak from my own experience: swap is good to have on a laptop.&lt;/p&gt;
&lt;p&gt;First of all, hibernation requires swap. Even though I rarely put my laptop into hibernation manually, I still want it to hibernate automatically when the battery is depleted.&lt;/p&gt;
&lt;p&gt;Second, modern web pages and browsers consume a lot of memory. While a laptop may only have 8 GB, or even 4 GB, of RAM, I don&apos;t want my laptops to crash just because I open too many tabs in the browser.&lt;/p&gt;
&lt;p&gt;Nowadays, laptops use NVMe SSDs. This means the I/O speed is much higher than it was with traditional SATA hard drives and older SSDs. And the I/O speed of swap is therefore much higher than it was in the old days. My recently purchased XPS 13 is the first laptop I have that uses an NVMe SSD. And I immediately noticed the difference in swap performance when I opened too many tabs in my browser and hit OOM.&lt;/p&gt;
</content:encoded></item><item><title>Murmur: Dell XPS 13 7390</title><link>https://piyueh.github.io/posts/2019-12-22-murmur-dell-xps-13-7390/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-12-22-murmur-dell-xps-13-7390/</guid><pubDate>Sun, 22 Dec 2019 09:32:37 GMT</pubDate><content:encoded>&lt;p&gt;I got a great deal on a Dell XPS 13 7390 on Black Friday this year. It&apos;s a regular 7390, not the 2-in-1 model. Still, it&apos;s a really fantastic machine.&lt;/p&gt;
&lt;p&gt;I had never used any high-end laptop before. I spend most of my time on local desktops, workstations, and remote clusters, and I rarely need a laptop except when I am out of town. My travel laptop had been a $180 Chromebook with Arch installed for a couple of years before this Black Friday. It has a great keyboard. That means as long as internet access is good, I can work efficiently with my cheap Chromebook during trips.&lt;/p&gt;
&lt;p&gt;But this year, since I was really having a difficult time, I decided to buy something luxurious on Black Friday to cheer myself up. I had been watching the XPS 13 for many years, ever since Costco started selling them in stores. Every time I was in a Costco, I spent a lot of time just staring at the XPS. I always convinced myself that there was no need for a new laptop, especially a fancy and expensive one.&lt;/p&gt;
&lt;p&gt;The deal I got was around $840 for a 10th-generation i7, a 1080p display, 8 GB of RAM, a 256 GB NVMe SSD, and a less problematic Wi-Fi card. This is the developer edition, so it doesn&apos;t have a fingerprint sensor or Windows. It is a great deal for me. After all, I only use Arch and don&apos;t need Windows, and fingerprint sensors do not work well on Linux, at least from what I have heard.&lt;/p&gt;
&lt;p&gt;The only unsatisfying thing is the RAM. The RAM is soldered onto the motherboard. It&apos;s not easy, if it is even possible, to upgrade soldered RAM. Some people also complain that the RAM is DDR3-2133, which is kind of old by modern standards. But I&apos;m actually okay with that. It is unlikely that I would feel a huge performance difference between DDR3 and DDR4 for daily use, especially since I don&apos;t need this laptop to do heavy jobs. I simply want a laptop that is fancy enough and can make me happy. As long as the keyboard feels right, the display is good, and the internet is good, I can work with it.&lt;/p&gt;
&lt;p&gt;This Dell XPS 13 is actually the first laptop I have ever had that cost more than $500. (I do have a Lenovo W540, but I don&apos;t think it can really be called a laptop. It&apos;s basically a brick and not something I can put on my lap...) So I don&apos;t really know how good it is compared to other laptops in the same class. I&apos;m not a professional laptop reviewer or YouTuber, and I&apos;m not able to come up with beautiful words to describe it.&lt;/p&gt;
&lt;p&gt;The only word I can think of is AMAZING.&lt;/p&gt;
&lt;p&gt;The keyboard is amazing. I don&apos;t understand keyboard jargon such as actuation force or travel distance. But I am very used to the Adesso MKB-135B mechanical keyboard, and I rarely find a keyboard that can provide a similar typing experience, not even close. The reason I loved my previous $180 Chromebook so much is that the keyboard was not bad. And the keyboard on this XPS is even better. My fingers feel like they are flying when I type on XPS keyboards. The keys do not feel like cheap plastic.&lt;/p&gt;
&lt;p&gt;The second thing I love about the laptop is the display. It&apos;s not a 4K display, not an OLED display, and not a touch screen. But I think it does have excellent color and brightness. The thing I hated most about my previous $180 Chromebook was the display. Again, I&apos;m not a graphics guy, so I don&apos;t know much about color. But compared to my $180 Chromebook and all the decent $200 monitors I have used, the XPS seems to give me a more vivid image. I don&apos;t know the reason behind it, but I do believe it is because of the color capability.&lt;/p&gt;
&lt;p&gt;The last thing I love about the XPS is its look and dimensions. It&apos;s only about 0.3 to 0.4 inch thick and has a skinny bezel. The small footprint of the XPS is famous, so there is no need to talk much about it. As for hardware performance, I don&apos;t really have strong feelings about it. I do all my heavy computations on remote machines. And I don&apos;t play games on the XPS either.&lt;/p&gt;
&lt;p&gt;This laptop has only USB-C ports, which is somewhat annoying, since many gadgets still use USB-A. And I also need a USB-C-to-HDMI converter when I use this laptop for presentations. But on the other hand, the XPS has a microSD card reader. I kind of like that. I have many microSD cards from old cameras and phones. I can put them into my XPS, though I don&apos;t know when I am really going to need them.&lt;/p&gt;
&lt;p&gt;However, I can still say one bad thing about the XPS: the cooling system. Even though I don&apos;t do heavy computations on the XPS, I sometimes compile code with it. And that&apos;s when I immediately feel the heat at the bottom of the laptop. I think one day I&apos;ll probably reapply the thermal paste, using a better paste, or even upgrade to a better heat pipe if there is one.&lt;/p&gt;
&lt;p&gt;Another issue is the Intel GPU. X11 did not perform that well with the UHD GPU. So I had to migrate my graphical environment to a Wayland-based system. I chose Sway WM, which is i3-compatible. I&apos;ve been using i3 WM for a long time, so I thought it wouldn&apos;t be a problem if Sway was truly i3-compatible. But it turned out there were a lot of things I had to change. That is another story. Maybe I&apos;ll write about it next time.&lt;/p&gt;
&lt;p&gt;But what I can say is that Wayland is also amazing when running on this XPS. I really love this XPS 13. Now, even when I am at home, I still spend a lot of time using this laptop.&lt;/p&gt;
</content:encoded></item><item><title>Optimize TensorFlow &amp; Keras models with L-BFGS from TensorFlow Probability</title><link>https://piyueh.github.io/posts/2019-11-02-optimize-tensorflow-keras-models-with-l-bfgs-from-tensorflow-probability/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-11-02-optimize-tensorflow-keras-models-with-l-bfgs-from-tensorflow-probability/</guid><pubDate>Sat, 02 Nov 2019 22:31:04 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This post showcases a workaround to optimize a &lt;code&gt;tf.keras.Model&lt;/code&gt; model with a TensorFlow-based L-BFGS optimizer from TensorFlow Probability. The complete code can be found at my GitHub Gist &lt;a href=&quot;https://gist.github.com/piyueh/712ec7d4540489aad2dcfb80f9a54993&quot;&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Update (06/08/2020): I&apos;ve updated the code on GitHub Gist to show how to save loss values into a list when using the &lt;code&gt;@tf.function&lt;/code&gt; decorator. But I didn&apos;t update the blog post here, so the code line numbers may not match the code on GitHub.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;While SGD, Adam, and similar optimizers now dominate the training of deep neural networks, some people, including me, may still want to use second-order methods such as L-BFGS.&lt;/p&gt;
&lt;p&gt;The problem is that TensorFlow 2.0 does not have L-BFGS. PyTorch provides L-BFGS, so using Keras with a PyTorch backend might sound like a possible workaround. But I don&apos;t use original Keras. I use TensorFlow 2.0 and build Keras models with the &lt;code&gt;tf.keras&lt;/code&gt; module. That means I cannot simply switch the backend. And it is difficult for me to migrate my code to original Keras because my code contains many customized parts that require TensorFlow 2.0.&lt;/p&gt;
&lt;p&gt;Another workaround is to use the L-BFGS solver from SciPy to train a &lt;code&gt;tf.keras.Model&lt;/code&gt; or its subclasses. We can find some example code for that approach through a quick search. The problem, however, is that standard SciPy is not GPU-capable. And many people like me use TensorFlow because we need GPU computing. In addition, I personally do not think SciPy is ideal for serious large-scale calculations. It is more of a prototyping tool than something I would want to run on an HPC cluster. That is just my personal opinion.&lt;/p&gt;
&lt;p&gt;Fortunately, a TensorFlow-based L-BFGS solver exists in &lt;strong&gt;&lt;a href=&quot;https://www.tensorflow.org/probability/&quot;&gt;TensorFlow Probability&lt;/a&gt;&lt;/strong&gt;. The API documentation for this solver is &lt;strong&gt;&lt;a href=&quot;https://www.tensorflow.org/probability/api_docs/python/tfp/optimizer/lbfgs_minimize&quot;&gt;here&lt;/a&gt;&lt;/strong&gt;. We can use it through something like &lt;code&gt;import tensorflow_probability as tfp&lt;/code&gt;, and then call &lt;code&gt;result = tfp.optimizer.lbfgs_minimize(...)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The returned object, &lt;code&gt;result&lt;/code&gt;, contains several pieces of information, and the final optimized parameters are stored in &lt;code&gt;result.position&lt;/code&gt;. If you are using a GPU version of TensorFlow, then this L-BFGS solver should also run on the GPU.&lt;/p&gt;
&lt;p&gt;Apparently, the solver is not implemented as a subclass of &lt;code&gt;tf.keras.optimizers.Optimizer&lt;/code&gt;. So we cannot use it directly with &lt;code&gt;model.compile(...)&lt;/code&gt; and &lt;code&gt;model.fit(...)&lt;/code&gt;. The solver is just a function. We need some workaround or wrapper to use it.&lt;/p&gt;
&lt;p&gt;Let&apos;s first see the arguments of this function:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Arguments of &lt;code&gt;tfp.optimizer.lbfgs_minimize&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;tfp.optimizer.lbfgs_minimize(
    value_and_gradients_function,
    initial_position,
    num_correction_pairs=10,
    tolerance=1e-08,
    x_tolerance=0,
    f_relative_tolerance=0,
    initial_inverse_hessian_estimate=None,
    max_iterations=50,
    parallel_iterations=1,
    stopping_condition=None,
    name=None
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;value_and_gradients_function&lt;/code&gt; is a function, or a callable object, that returns the loss and the gradients with respect to parameters. This callable object should take in the parameters that we want to optimize, which in this case are the model&apos;s trainable parameters, i.e., the kernels and biases of trainable layers.&lt;/p&gt;
&lt;p&gt;The first notable thing is that &lt;code&gt;value_and_gradients_function&lt;/code&gt; takes model parameters, not training data. The second thing is that the model parameters fed into &lt;code&gt;value_and_gradients_function&lt;/code&gt; must be a 1D &lt;code&gt;tf.Tensor&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But TensorFlow and Keras store trainable model parameters as a list of multidimensional &lt;code&gt;tf.Variable&lt;/code&gt; objects. We can easily see this with &lt;code&gt;print(model.trainable_variables)&lt;/code&gt;, assuming &lt;code&gt;model&lt;/code&gt; is an instance of &lt;code&gt;tf.keras.Model&lt;/code&gt; or one of its subclasses. This means we need a way to transform a list of multidimensional &lt;code&gt;tf.Variable&lt;/code&gt; objects into a single 1D tensor. This can be done with &lt;code&gt;tf.dynamic_stitch&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We also need a way to convert a 1D &lt;code&gt;tf.Tensor&lt;/code&gt; back to a list of multidimensional &lt;code&gt;tf.Tensor&lt;/code&gt;, &lt;code&gt;tf.Variable&lt;/code&gt;, or &lt;code&gt;numpy.ndarray&lt;/code&gt; objects so that we can update the model parameters. Under most circumstances, we can treat &lt;code&gt;tf.Variable&lt;/code&gt; and &lt;code&gt;tf.Tensor&lt;/code&gt; similarly for this purpose.&lt;/p&gt;
&lt;p&gt;There are two ways to update a model&apos;s parameters:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We can use &lt;code&gt;model.set_weights(params)&lt;/code&gt; to update the values of the parameters. In this case, &lt;code&gt;params&lt;/code&gt; is a list of multidimensional &lt;code&gt;numpy.ndarray&lt;/code&gt;. And we need to convert the aforementioned 1D &lt;code&gt;tf.Tensor&lt;/code&gt; to &lt;code&gt;params&lt;/code&gt;. In TensorFlow 2.0, this is not difficult because of the default eager execution behavior. We first partition the 1D &lt;code&gt;tf.Tensor&lt;/code&gt; with &lt;code&gt;tf.dynamic_partition&lt;/code&gt; to a list of tensors, convert the list of tensors to a list of &lt;code&gt;numpy.ndarray&lt;/code&gt; with &lt;code&gt;tensor.numpy()&lt;/code&gt;, and then reshape each array to the corresponding shape. Finally, we can call &lt;code&gt;model.set_weights(params)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The other way is more computationally efficient and can work in graph mode without eager execution. Each element in &lt;code&gt;model.trainable_variables&lt;/code&gt; is a &lt;code&gt;tf.Variable&lt;/code&gt;, and it provides an &lt;code&gt;assign&lt;/code&gt; method to update its value. So we first partition the 1D &lt;code&gt;tf.Tensor&lt;/code&gt; into a list of tensors with &lt;code&gt;tf.dynamic_partition&lt;/code&gt;. Next, we use a &lt;code&gt;for&lt;/code&gt; loop to reshape each tensor and assign it to the corresponding &lt;code&gt;tf.Variable&lt;/code&gt; in &lt;code&gt;model.trainable_variables&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The third thing is that when returning the gradients, the gradients should also be a 1D &lt;code&gt;tf.Tensor&lt;/code&gt; to match the expected format of &lt;code&gt;value_and_gradients_function&lt;/code&gt;. This again can be done with &lt;code&gt;tf.dynamic_stitch&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In addition, the argument &lt;code&gt;initial_position&lt;/code&gt; of &lt;code&gt;tfp.optimizer.lbfgs_minimize&lt;/code&gt; should contain the initial parameter values of the model. And of course, we should use &lt;code&gt;tf.dynamic_stitch&lt;/code&gt; to convert the initial model parameters into a 1D &lt;code&gt;tf.Tensor&lt;/code&gt; before passing them to &lt;code&gt;initial_position&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In a nutshell, when we create a function for the &lt;code&gt;value_and_gradients_function&lt;/code&gt; argument, that function should store the following information:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;the &lt;code&gt;tf.keras.Model&lt;/code&gt; model we want to use,&lt;/li&gt;
&lt;li&gt;the loss function to use,&lt;/li&gt;
&lt;li&gt;the training data that we want to evaluate the loss,&lt;/li&gt;
&lt;li&gt;the information required by &lt;code&gt;tf.dynamic_stitch&lt;/code&gt; to convert a list of multidimensional &lt;code&gt;tf.Tensor&lt;/code&gt; to a 1D &lt;code&gt;tf.Tensor&lt;/code&gt;, and&lt;/li&gt;
&lt;li&gt;the information required by &lt;code&gt;tf.dynamic_partition&lt;/code&gt; to convert a 1D &lt;code&gt;tf.Tensor&lt;/code&gt; to a list of multidimensional &lt;code&gt;tf.Tensor&lt;/code&gt; or &lt;code&gt;numpy.ndarray&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We can define a function factory to create such a function for us. Here&apos;s an example:
&lt;a href=&quot;https://gist.github.com/piyueh/712ec7d4540489aad2dcfb80f9a54993&quot;&gt;Code snippet&lt;/a&gt; (&lt;code&gt;tf_keras_tfp_lbfgs.py&lt;/code&gt;, lines 25-107)&lt;/p&gt;
&lt;p&gt;And here&apos;s an example of how to use this function factory together with &lt;code&gt;tfp.optimizer.lbfgs_minimize&lt;/code&gt; to train a &lt;code&gt;tf.keras.Model&lt;/code&gt; model:
&lt;a href=&quot;https://gist.github.com/piyueh/712ec7d4540489aad2dcfb80f9a54993&quot;&gt;Code snippet&lt;/a&gt; (&lt;code&gt;tf_keras_tfp_lbfgs.py&lt;/code&gt;, lines 131-152)&lt;/p&gt;
&lt;p&gt;The complete example code can be found at my GitHub Gist &lt;strong&gt;&lt;a href=&quot;https://gist.github.com/piyueh/712ec7d4540489aad2dcfb80f9a54993&quot;&gt;here&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Finally, the example code is only meant to give a sense of how to use the L-BFGS solver from TensorFlow Probability. Using a function factory is not the only option. &lt;code&gt;value_and_gradients_function&lt;/code&gt; can be any callable object. So we could also wrap the model in a Python class and implement &lt;code&gt;__call__&lt;/code&gt;. It is entirely up to us.&lt;/p&gt;
</content:encoded></item><item><title>tf.keras.callbacks.EarlyStopping not working as expected</title><link>https://piyueh.github.io/posts/2019-11-01-tf-keras-callbacks-earlystopping-not-working-as-expected/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-11-01-tf-keras-callbacks-earlystopping-not-working-as-expected/</guid><pubDate>Fri, 01 Nov 2019 21:27:33 GMT</pubDate><content:encoded>&lt;p&gt;&lt;code&gt;tf.keras.callbacks.EarlyStopping&lt;/code&gt; is used to terminate a training if a monitored quantity satisfies some criterion. For example, in the following code snippet, the training will stop before reaching the target epoch (&lt;code&gt;10000&lt;/code&gt; in this case) if the training loss has not improved for 3 epochs in a roll:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;stop = tf.keras.callbacks.EarlyStopping(
            monitor=&quot;loss&quot;, min_delta=1e-3, patience=3)
model.fit(..., epochs=10000, callbacks=[stop])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;min_delta=1e-3&lt;/code&gt; represents how large a change must be to count as an improvement.&lt;/p&gt;
&lt;p&gt;In the example above, some people, and I admit I used to be one of them, may expect that when the training is stopped by &lt;code&gt;EarlyStopping&lt;/code&gt;, the last 3 or 4 epochs should have similar values because the loss is no longer improving. In other words, people may think the training stopped because the loss &lt;strong&gt;&lt;em&gt;converged&lt;/em&gt;&lt;/strong&gt; to some value, and continuing the training would not reduce the loss much.&lt;/p&gt;
&lt;p&gt;That expectation corresponds to a situation where the last 4 losses are, for example, &lt;code&gt;0.01&lt;/code&gt;, &lt;code&gt;0.0105&lt;/code&gt;, &lt;code&gt;0.0092&lt;/code&gt;, and &lt;code&gt;0.0099&lt;/code&gt;. The last 3 losses do not differ from &lt;code&gt;0.01&lt;/code&gt; by more than &lt;code&gt;1e-3&lt;/code&gt;. But that expectation is &lt;strong&gt;WRONG&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Before we look into the source code to understand what &lt;code&gt;EarlyStopping&lt;/code&gt; does, let&apos;s read the &lt;a href=&quot;https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/EarlyStopping&quot;&gt;API documentation&lt;/a&gt; again:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Stop training when a monitored quantity has stopped improving.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It only says &quot;&lt;em&gt;a monitored quantity &lt;strong&gt;has stopped improving&lt;/strong&gt;&lt;/em&gt;&quot;. It does not say &quot;&lt;em&gt;a monitored quantity &lt;strong&gt;has converged&lt;/strong&gt;&lt;/em&gt;&quot;.&lt;/p&gt;
&lt;p&gt;So it is also possible that the training is stopped because the loss blew up for 3 epochs in a row. For example, if the losses of the last 4 epochs are &lt;code&gt;0.01&lt;/code&gt;, &lt;code&gt;1.2&lt;/code&gt;, &lt;code&gt;2.05&lt;/code&gt;, and &lt;code&gt;3.0&lt;/code&gt;, &lt;code&gt;EarlyStopping&lt;/code&gt; also stops the training.&lt;/p&gt;
&lt;p&gt;Because training may stop due to blowing up, we are not guaranteed to get an optimized model at the last epoch. Even worse, we may end up with a model that has a very large loss. That is why &lt;code&gt;EarlyStopping&lt;/code&gt; has an optional argument called &lt;code&gt;restore_best_weights&lt;/code&gt;. It helps recover the model weights that gave us the best prediction during training.&lt;/p&gt;
&lt;p&gt;Now let&apos;s read the source code of &lt;code&gt;EarlyStopping&lt;/code&gt;. The code of the current version is &lt;a href=&quot;https://github.com/tensorflow/tensorflow/blob/1cf0898dd4331baf93fe77205550f2c2e6c90ee5/tensorflow/python/keras/callbacks.py#L1221-L1238&quot;&gt;here&lt;/a&gt;:
&lt;a href=&quot;https://github.com/tensorflow/tensorflow/blob/1cf0898dd4331baf93fe77205550f2c2e6c90ee5/tensorflow/python/keras/callbacks.py#L1221-L1238&quot;&gt;&lt;img src=&quot;https://pychao.com/wp-content/uploads/2019/11/FireShot-Capture-005-tensorflow_callbacks.py-at-r2.0-%C2%B7-tensorflow_tensorflow-github.com_.png&quot; alt=&quot;Code of EarlyStopping.on_epoch_end&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Code of &lt;code&gt;EarlyStopping.on_epoch_end&lt;/code&gt; (snippet from TensorFlow&apos;s GitHub repo)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;self.monitor_op&lt;/code&gt; is &lt;code&gt;&amp;lt;&lt;/code&gt; (less than) for quantities like loss or root mean squared error, and it is &lt;code&gt;&amp;gt;&lt;/code&gt; (greater than) for quantities like accuracy.&lt;/p&gt;
&lt;p&gt;We can see from line 1225 that if &lt;strong&gt;the current loss + min_delta&lt;/strong&gt; (&lt;code&gt;1e-3&lt;/code&gt; in our case) is less than &lt;strong&gt;the best loss in the training history&lt;/strong&gt;, it is treated as an improvement and updates the best-loss record. Any situation in which &lt;strong&gt;the current loss + min_delta&lt;/strong&gt; is not less than &lt;strong&gt;the best record&lt;/strong&gt; (line 1230) is treated as &quot;not improving&quot; and increases the count of consecutive epochs without improvement.&lt;/p&gt;
&lt;p&gt;That &quot;any situation&quot; obviously includes the case where the current loss is greater than the best record. So &lt;code&gt;EarlyStopping&lt;/code&gt; will stop training if the monitored quantity blows up.&lt;/p&gt;
&lt;p&gt;Anyway, coming from the world of traditional numerical methods, I expected that an iterative solver would stop early only when the residual, i.e. the loss, converged to some value and no longer changed significantly. If I want to terminate a solver early because it is blowing up, I would usually use another mechanism that detects whether the solver &lt;strong&gt;&lt;em&gt;diverges&lt;/em&gt;&lt;/strong&gt;. I rarely combine convergence detection and divergence detection into a single mechanism.&lt;/p&gt;
&lt;p&gt;And when a solver stops because of divergence, I do not usually say that it &quot;stops&quot; in the same sense. I tend to use the word &quot;stop&quot; only when describing a solver that finishes successfully. And obviously, divergence is not a successful solve. That is why I did not really expect &lt;code&gt;tf.keras.callbacks.EarlyStopping&lt;/code&gt; to terminate a training process when the loss blows up.&lt;/p&gt;
</content:encoded></item><item><title>[NumPy] Reminder: use correct norms to evaluate orders of convergence</title><link>https://piyueh.github.io/posts/2019-10-24-numpy-reminder-use-correct-norms-to-evaluate-orders-of-convergence/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-10-24-numpy-reminder-use-correct-norms-to-evaluate-orders-of-convergence/</guid><pubDate>Thu, 24 Oct 2019 20:13:50 GMT</pubDate><content:encoded>&lt;p&gt;I wrote this post to remind myself of something.&lt;/p&gt;
&lt;p&gt;When evaluating the order of convergence of numerical simulation results, we usually use either the infinity norm or the L2 norm. In practice, I usually only use the L2 norm, unless I am dealing with a numerical method where the infinity norm and the L2 norm have different orders of convergence.&lt;/p&gt;
&lt;p&gt;But if you are using Python and NumPy for the evaluation, be aware that &lt;code&gt;numpy.linalg.norm&lt;/code&gt;, and also &lt;code&gt;scipy.linalg.norm&lt;/code&gt;, returns the l2 norm, not the L2 norm. Although the official documentation does show the equation being used, I rarely read the documentation for this function that carefully. It is just a norm calculation. What could go wrong? That was what I thought.&lt;/p&gt;
&lt;p&gt;Checking the order of convergence is an essential part of verifying a numerical simulation program. What happened to me was that I could not get the theoretical order of convergence for one of my programs when using the L2 norm. I thought there might be a bug in the code, so I spent about a day debugging it and found nothing.&lt;/p&gt;
&lt;p&gt;Then I suddenly decided to use the infinity norm. It gave me the expected theoretical value. That was the moment when I seriously read the official documentation of &lt;code&gt;numpy.linalg.norm&lt;/code&gt; for the first time.&lt;/p&gt;
</content:encoded></item><item><title>The implicit dtype conversion in the call and **call** methods of tf.keras.Model</title><link>https://piyueh.github.io/posts/2019-10-14-the-implicit-dtype-conversion-in-the-call-and-__call__-methods-of-tf-keras-model/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-10-14-the-implicit-dtype-conversion-in-the-call-and-__call__-methods-of-tf-keras-model/</guid><pubDate>Mon, 14 Oct 2019 21:32:48 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;Note: the content in this post was tested with the GPU version of TensorFlow 2.0.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I need &lt;code&gt;float64&lt;/code&gt; for my models. However, I did not realize until recently that even though the &lt;code&gt;dtype&lt;/code&gt; of all layers in my models is &lt;code&gt;tf.float64&lt;/code&gt;, and even though my &lt;code&gt;x&lt;/code&gt; is a &lt;code&gt;tf.float64&lt;/code&gt; tensor, when I call &lt;code&gt;model(x)&lt;/code&gt;, the model still treats &lt;code&gt;x&lt;/code&gt; as a &lt;code&gt;tf.float32&lt;/code&gt; tensor.&lt;/p&gt;
&lt;p&gt;Here&apos;s a simple example to check this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class TestModel(tf.keras.Model):
    def __init__(self):
        super(TestModel, self).__init__()
    def call(self, inputs, training=False):
        print(&quot;The type of input: {}&quot;.format(inputs.dtype))
        return inputs
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then, in any Python interpreter or script:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;x = tf.constant(1.0, dtype=tf.float64)
print(&quot;The type of x: {}&quot;.format(x.dtype))
model = TestModel()
y = model(x)
print(&quot;The type of output: {}&quot;.format(y.dtype))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the output, we should see something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;The type of x: &amp;lt;dtype: &apos;float64&apos;&amp;gt;
The type of input: &amp;lt;dtype: &apos;float32&apos;&amp;gt;
The type of output: &amp;lt;dtype: &apos;float32&apos;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To solve this issue, we also have to provide the &lt;code&gt;dtype&lt;/code&gt; argument to our model. Something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class TestModel(tf.keras.Model):
    def __init__(self, dtype=tf.float64):
        super(TestModel, self).__init__(dtype=dtype)
    def call(self, inputs, training=False):
        print(&quot;The type of input: {}&quot;.format(inputs.dtype))
        return inputs
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we can see that &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;inputs&lt;/code&gt;, and &lt;code&gt;y&lt;/code&gt; are all &lt;code&gt;tf.float64&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;The type of x: &amp;lt;dtype: &apos;float64&apos;&amp;gt;
The type of input: &amp;lt;dtype: &apos;float64&apos;&amp;gt;
The type of output: &amp;lt;dtype: &apos;float64&apos;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is not a complicated problem. But I was not aware of it because the official documentation did not mention it, at least not at the time I wrote this post. And I did not get any warning or error message during runtime either.&lt;/p&gt;
&lt;p&gt;The underlying reason is that in a parent class of &lt;code&gt;tf.keras.Model&lt;/code&gt;, namely &lt;code&gt;tf.keras.layers.Layer&lt;/code&gt;, the &lt;code&gt;__call__&lt;/code&gt; method calls a casting method, &lt;a href=&quot;https://github.com/tensorflow/tensorflow/blob/1cf0898dd4331baf93fe77205550f2c2e6c90ee5/tensorflow/python/keras/engine/base_layer.py#L888&quot;&gt;&lt;code&gt;_maybe_cast_input&lt;/code&gt;&lt;/a&gt;. And &lt;code&gt;_maybe_cast_input&lt;/code&gt; will cast &lt;code&gt;inputs&lt;/code&gt; to the model&apos;s &lt;code&gt;dtype&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So we must specify the model&apos;s &lt;code&gt;dtype&lt;/code&gt; as the one we actually want. Otherwise, no matter how we set up our data or layers, the model will always use &lt;code&gt;tf.float32&lt;/code&gt; by default.&lt;/p&gt;
&lt;p&gt;Another workaround is to force TensorFlow to use &lt;code&gt;tf.float64&lt;/code&gt; as the default floating-point type. We can do that through &lt;code&gt;tf.keras.backend.set_floatx(&apos;float64&apos;)&lt;/code&gt;.&lt;/p&gt;
</content:encoded></item><item><title>Solution to nonfunctioning HP LaserJet p1102w due to newer versions of hplip in Linux</title><link>https://piyueh.github.io/posts/2019-10-04-solution-to-nonfunctioning-hp-laserjet-p1102w-due-to-newer-versions-of-hplip/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-10-04-solution-to-nonfunctioning-hp-laserjet-p1102w-due-to-newer-versions-of-hplip/</guid><pubDate>Fri, 04 Oct 2019 19:18:48 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Linux distribution:&lt;/strong&gt; Arch Linux&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Symptoms:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;hp-setup&lt;/code&gt; can not detect the p1102w printer when using USB connection.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hp-setup&lt;/code&gt; can not find the p1102w printer through manual WiFi IP connection.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hplip&lt;/code&gt; is at version &lt;code&gt;3.19.x&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Open the file &lt;code&gt;/usr/share/hplip/data/models/models.dat&lt;/code&gt;, and search for the entry with keyword &lt;code&gt;p_1102w&lt;/code&gt;. There should be an entry with the name &lt;code&gt;hp_laserjet_professional_p_1102w&lt;/code&gt;. See the problem here? It should be &lt;code&gt;hp_laserjet_professional_p1102w&lt;/code&gt;. No underscore should be present between &lt;code&gt;p&lt;/code&gt; and &lt;code&gt;1102w&lt;/code&gt;. So the solution is simple: just remove the underscore. Also, inside the entry, there&apos;s a property: &lt;code&gt;model1=HP LaserJet Professional P 1102w Printer&lt;/code&gt;. There&apos;s an extra space between &lt;code&gt;P&lt;/code&gt; and &lt;code&gt;1102w&lt;/code&gt;. I&apos;m not sure if this property will affect the functioning of the printer, but I prefer to remove the space. So that property will be: &lt;code&gt;model1=HP LaserJet Professional P1102w Printer&lt;/code&gt;. You may need &lt;code&gt;root&lt;/code&gt; or &lt;code&gt;sudo&lt;/code&gt; privilege to modify the file.&lt;/p&gt;
</content:encoded></item><item><title>Different calling methods of the metric objects in Keras</title><link>https://piyueh.github.io/posts/2019-09-30-different-calling-methods-of-the-metric-objects-in-keras/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-09-30-different-calling-methods-of-the-metric-objects-in-keras/</guid><pubDate>Mon, 30 Sep 2019 22:44:17 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;Disclaimer: I use the Keras interface from TensorFlow 2.0.0-rc1, so I&apos;m not sure if the content applies to the original Keras library or other versions of TensorFlow. And note that TensorFlow 2.0.0-rc1 uses eager-execution mode by default.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Let&apos;s say we have a metric object &lt;code&gt;m = tf.keras.metrics.Mean()&lt;/code&gt;. There are two ways to add a number, for example &lt;code&gt;10&lt;/code&gt;, to the metric &lt;code&gt;m&lt;/code&gt;: the first way is to call &lt;code&gt;m.update_state(10)&lt;/code&gt;, and the other way is to simply call &lt;code&gt;m(10)&lt;/code&gt;. When we want to know the current mean value, we then use &lt;code&gt;m.result()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I was wondering what the difference is between &lt;code&gt;m(10)&lt;/code&gt; and &lt;code&gt;m.update_state(10)&lt;/code&gt;, because I could not find an explanation in the documentation of &lt;code&gt;tf.keras.metrics.Mean&lt;/code&gt; (see &lt;a href=&quot;https://www.tensorflow.org/api_docs/python/tf/keras/metrics/Mean&quot;&gt;here&lt;/a&gt;). The special member function of a Python class that allows us to use something like &lt;code&gt;m(10)&lt;/code&gt; is &lt;code&gt;__call__()&lt;/code&gt;. But in that documentation, there is no mention of &lt;code&gt;__call__()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;And why did I care? Because in the official tutorial &lt;a href=&quot;https://www.tensorflow.org/tutorials/customization/custom_training_walkthrough&quot;&gt;here&lt;/a&gt;, the tutorial uses the second way to add a value to metrics without explanation.&lt;/p&gt;
&lt;p&gt;If we use an interactive environment, like an IPython console or a Jupyter Notebook, we can find some information about the two methods through &lt;code&gt;help(tf.keras.metrics.Mean)&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;tf.keras.metrics.Mean.update_state&lt;/code&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Accumulates statistics for computing the reduction metric. For example, if &lt;code&gt;values&lt;/code&gt; is [1, 3, 5, 7] and reduction=SUM_OVER_BATCH_SIZE, then the value of &lt;code&gt;result()&lt;/code&gt; is 4. If the &lt;code&gt;sample\_weight&lt;/code&gt; is specified as [1, 1, 0, 0] then the value of &lt;code&gt;result()&lt;/code&gt; would be 2.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;tf.keras.metrics.Mean.__call__&lt;/code&gt;: &amp;gt; Accumulates statistics and then computes metric result value.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So apparently, &lt;code&gt;update_state&lt;/code&gt; simply updates the sequence of numbers but does not do the calculation, which in this example means averaging the numbers. And &lt;code&gt;__call__&lt;/code&gt; updates the sequence and also does the calculation.&lt;/p&gt;
&lt;p&gt;From this point of view, I would guess that calling &lt;code&gt;__call__&lt;/code&gt;, or &lt;code&gt;m(10)&lt;/code&gt; in our example, is less efficient. After all, we do not really need to know the current mean value every time we add a number to the sequence.&lt;/p&gt;
&lt;p&gt;We can actually see this in the source code. As indicated by &lt;code&gt;help(tf.keras.metrics.Mean)&lt;/code&gt;, the method &lt;code&gt;__call__&lt;/code&gt; is inherited from &lt;code&gt;tf.keras.metrics.Metric&lt;/code&gt;. Its source code can be viewed &lt;a href=&quot;https://github.com/tensorflow/tensorflow/blob/64c3d382cadf7bbe8e7e99884bede8284ff67f56/tensorflow/python/keras/metrics.py#L162-L193&quot;&gt;here&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; def __call__(self, *args, **kwargs):
    &quot;&quot;&quot;Accumulates statistics and then computes metric result value.
    Args:
      *args:
      **kwargs: A mini-batch of inputs to the Metric,
        passed on to `update_state()`.
    Returns:
      The metric value tensor.
    &quot;&quot;&quot;

    def replica_local_fn(*args, **kwargs):
      &quot;&quot;&quot;Updates the state of the metric in a replica-local context.&quot;&quot;&quot;
      update_op = self.update_state(*args, **kwargs)  # pylint: disable=not-callable
      with ops.control_dependencies([update_op]):
        result_t = self.result()  # pylint: disable=not-callable

        # We are adding the metric object as metadata on the result tensor.
        # This is required when we want to use a metric with `add_metric` API on
        # a Model/Layer in graph mode. This metric instance will later be used
        # to reset variable state after each epoch of training.
        # Example:
        #   model = Model()
        #   mean = Mean()
        #   model.add_metric(mean(values), name=&apos;mean&apos;)
        result_t._metric_obj = self  # pylint: disable=protected-access
        return result_t

    from tensorflow.python.keras.distribute import distributed_training_utils  # pylint:disable=g-import-not-at-top
    return distributed_training_utils.call_replica_local_fn(
        replica_local_fn, *args, **kwargs)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Removing the docstrings, we can see that &lt;code&gt;__call__&lt;/code&gt; is actually calling &lt;code&gt;update_state(...)&lt;/code&gt; and then &lt;code&gt;result()&lt;/code&gt;.&lt;/p&gt;
</content:encoded></item><item><title>Turning off the annoying stdout messages from TensorFlow 2.0rc</title><link>https://piyueh.github.io/posts/2019-09-26-turning-off-the-annoying-stdout-messages-from-tensorflow-2-0rc/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-09-26-turning-off-the-annoying-stdout-messages-from-tensorflow-2-0rc/</guid><pubDate>Thu, 26 Sep 2019 18:54:40 GMT</pubDate><content:encoded>&lt;p&gt;&lt;em&gt;Disclaimer: I only use the GPU version of TensorFlow v2.0.0-rc1, so I don&apos;t know if this works with other versions.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When writing TensorFlow code in Python scripts and running the scripts in a terminal, we usually get a bunch of messages in stdout. The messages log information from the initialization stage of TensorFlow. These messages are annoying to many people. The messages come from both the underlying C++ code and the Python code of TensorFlow. So we need to disable the two sources in different ways. If we install TensorFlow through &lt;code&gt;conda&lt;/code&gt; or &lt;code&gt;pip&lt;/code&gt;, then the C++ code is already compiled, and we don&apos;t have any way to modify the C++ source code. Fortunately, the messages coming from this source can be controlled by an environment variable, &lt;code&gt;TF_CPP_MIN_LOG_LEVEL&lt;/code&gt;. In Linux, before running Python scripts, we can simply do something like &lt;code&gt;$ export TF_CPP_MIN_LOG_LEVEL=2&lt;/code&gt;. But I prefer to hard-code this environment variable in my Python scripts because I&apos;m lazy. I add the following code in my Python scripts &lt;strong&gt;&lt;em&gt;before the code uses any TensorFlow object or function&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import os
os.environ[&quot;TF_CPP_MIN_LOG_LEVEL&quot;] = &quot;2&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This code does not necessarily need to be placed before &lt;code&gt;import tensorflow&lt;/code&gt;. But it must be placed before the code encounters any object or function coming from TensorFlow. I think the initialization of the TensorFlow package does not happen before this point. The second source of the messages can be turned off by the standard Python logging system:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import logging
logging.getLogger(&quot;tensorflow&quot;).setLevel(logging.ERROR)
logging.getLogger(&quot;tensorflow&quot;).addHandler(logging.NullHandler(logging.ERROR))
&lt;/code&gt;&lt;/pre&gt;
</content:encoded></item><item><title>How confident are you with your scientific simulation results?</title><link>https://piyueh.github.io/posts/2019-01-27-how-confident-are-you-with-your-scientific-simulation-results/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2019-01-27-how-confident-are-you-with-your-scientific-simulation-results/</guid><pubDate>Sun, 27 Jan 2019 08:13:33 GMT</pubDate><content:encoded>&lt;p&gt;Recently, I had a chance to be in a room with a bunch of Ph.D. students and faculty members from the mechanical engineering department. Faculty members were presenting their research to other faculty members and Ph.D. students.&lt;/p&gt;
&lt;p&gt;I quickly noticed that regardless of whether someone was an experimentalist, a theorist, or a numerical person like me, there were always slides showing results from numerical simulations. Some people prefer to call them computer simulations.&lt;/p&gt;
&lt;p&gt;At the end of the event, there was a 30-minute slot for all scholars to discuss anything they liked. No one raised any questions. It was quiet. So I decided to throw out a question to start some discussion: how confident are you in your computer simulations?&lt;/p&gt;
&lt;p&gt;I raised this question because I am not fully confident in any numerical simulation result I produce. Don&apos;t get me wrong. I&apos;m not attacking computer simulations, and I am a pure numerical guy. I was a simulation engineer in industry in the past, and now I am a Ph.D. student in numerical methods in academia.&lt;/p&gt;
&lt;p&gt;But I have always had this question in my mind because of a past experience. A long time ago, before I returned to academia, I was a simulation engineer in the manufacturing industry. I used my skills to provide suggestions to customers regarding various problems during manufacturing processes.&lt;/p&gt;
&lt;p&gt;Once, a customer came to me and wanted me to run simulations for a problematic mold they had. Usually, in a case like this, computer simulation is just a tool to help us design solutions, and we still need experiment-based tests to confirm them.&lt;/p&gt;
&lt;p&gt;But this case was urgent. The customer had no time to do careful examinations or tests. So they were going to modify their mold based only on my simulations. They told me the modification would cost one million dollars, and they had only one shot. So they wanted me to make sure the simulation results were correct.&lt;/p&gt;
&lt;p&gt;When I heard that the modification would cost one million dollars, I freaked out. I simply could not guarantee that the simulations were accurate enough. I was not confident enough because, as someone trained in numerical simulation, I know how many uncertainties and errors are involved.&lt;/p&gt;
&lt;p&gt;So I just could not tell them, “Yes, just trust the simulations and go ahead with the modification.”&lt;/p&gt;
&lt;p&gt;Ever since then, whenever I see someone showing results from computer simulations, I always want to ask whether they are confident enough in those simulations if one million dollars were to be spent based solely on those results, without any further experiment-based tests.&lt;/p&gt;
</content:encoded></item><item><title>Use ProtonMail for WordPress servers’ SMTP setting on Google Cloud Platform</title><link>https://piyueh.github.io/posts/2018-10-14-use-protonmail-for-wordpress-servers-smtp-setting-on-google-cloud-platform/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-10-14-use-protonmail-for-wordpress-servers-smtp-setting-on-google-cloud-platform/</guid><pubDate>Sun, 14 Oct 2018 22:36:06 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Updates&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Jun. 10, 2020: I&apos;m now using &lt;code&gt;pass&lt;/code&gt; instead of &lt;code&gt;gnome-keyring&lt;/code&gt;. I also use the newly introduced &lt;code&gt;--noninteractive&lt;/code&gt; option to run &lt;code&gt;protonmail-bridge&lt;/code&gt; in the background. See the updated post &lt;a href=&quot;https://pychao.com/2020/06/10/update-on-using-protonmail-bridge-on-headless-wordpress-linux-servers/&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Aug. 7, 2019: The version of Bridge used in the original post was 1.0.6. I recently upgraded Bridge to 1.1.6 and found that only one thing changed: the name of the executable. After upgrading, replace &lt;code&gt;Desktop-Bridge&lt;/code&gt; with &lt;code&gt;protonmail-bridge&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I have a WordPress server on Google Cloud Platform. And recently I just became a user of ProtonMail. So I was wondering if I could use ProtonMail&apos;s SMTP with the WordPress server so that the server can send emails/notifications with my ProtonMail address. ProtonMail provides a utility called &lt;a href=&quot;https://protonmail.com/bridge/&quot;&gt;Bridge&lt;/a&gt; to access its IMAP and SMTP servers. But the problem is that the instance on Google Cloud Platform is headless. And ProtonMail Bridge is not friendly to headless environments. Luckily, I was able to find a solution on the internet. See my &lt;a href=&quot;https://pychao.com/2018/10/13/use-protonmail-bridge-on-headless-linux-machines/&quot;&gt;previous post&lt;/a&gt;. After I got Bridge running on the instance, the other things are simple. And this post is about how I did it. If you want to try my solution in this post, please make sure:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You have an SMTP plugin installed on your WordPress server. For example, &lt;a href=&quot;https://wordpress.org/plugins/wp-mail-smtp/&quot;&gt;WP Mail SMTP&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;You have a ProtonMail Plus account, as Bridge does not work with free-tier ProtonMail accounts.&lt;/li&gt;
&lt;li&gt;You have made Bridge work on your server machine. If not, see my &lt;a href=&quot;https://pychao.com/2018/10/13/use-protonmail-bridge-on-headless-linux-machines/&quot;&gt;previous post&lt;/a&gt; for using Bridge in headless environments. If you want to use &lt;code&gt;pass&lt;/code&gt; instead of &lt;code&gt;gnome-keyring&lt;/code&gt;, see &lt;a href=&quot;https://pychao.com/2020/06/10/use-protonmail-bridge-on-headless-linux-servers-with-pass/&quot;&gt;this post&lt;/a&gt; instead.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Step 1: Set up Bridge through the command line&lt;/h2&gt;
&lt;p&gt;Use &lt;code&gt;$ Desktop-Bridge --cli&lt;/code&gt; (note: see the update above) to get into a non-graphical interactive interface of Bridge. Type &lt;code&gt;help&lt;/code&gt; in the interactive interface to see all supported commands. Basically, if nothing goes wrong, you may only need &lt;code&gt;login&lt;/code&gt; to log in to your account, &lt;code&gt;change mode&lt;/code&gt; to switch between combined/split modes, &lt;code&gt;info&lt;/code&gt; to see the local fake SMTP information, and &lt;code&gt;exit&lt;/code&gt; to exit Bridge.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;login&lt;/code&gt;: The interactive interface will ask for your ProtonMail username and password.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;change mode&lt;/code&gt;: In combined mode (the default), all emails going to all addresses under your ProtonMail account will be combined as if different addresses are just aliases of each other. And in split mode, different addresses are treated as if they are independent email addresses. It&apos;s up to you to choose either mode.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;info&lt;/code&gt;: You can find the information about the local fake SMTP server. The information contains the local IP address, port, username, and password. Don&apos;t be confused with the username and password seen here with your ProtonMail username and password. The username and password seen here are the ones to use the fake local SMTP server. If you use split mode, you may see several sections in the information, and each section refers to an address.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;exit&lt;/code&gt;: Completely exit Bridge. Bridge will not automatically run in the background after exit.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For example, I have two addresses under my ProtonMail account:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;abc@protonmail.com&lt;/em&gt; and &lt;em&gt;abc@pm.me&lt;/em&gt;, and I prefer the split mode. The output after I issue the &lt;code&gt;info&lt;/code&gt; command may look like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Configuration for abc@pm.me
IMAP Settings
Address: 127.0.0.1
IMAP port: 1143
Username: abc@pm.me
Password: defghijklmnop!@#

SMTP Settings
Address: 127.0.0.1
SMTP port: 1025
Username: abc@pm.me
Password: defghijklmnop!@#

Configuration for abc@protonmail.com
IMAP Settings
Address: 127.0.0.1
IMAP port: 1143
Username: abc@protonmail.com
Password: defghijklmnop!@#

SMTP Settings
Address: 127.0.0.1
SMTP port: 1025
Username: abc@protonmail.com
Password: defghijklmnop!@#

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I choose to use &lt;em&gt;abc@pm.me&lt;/em&gt; to send emails for my WordPress server, then the information in the subsection of &lt;code&gt;SMTP Settings&lt;/code&gt; under &lt;code&gt;Configuration for abc@pm.me&lt;/code&gt; is what I need later. Exit Bridge before getting into the next step.&lt;/p&gt;
&lt;h2&gt;Step 2: Run Bridge in the background&lt;/h2&gt;
&lt;p&gt;In headless environments, the only way to launch Bridge is through the command line &lt;code&gt;$ Desktop-Bridge --cli&lt;/code&gt;. However, this will get you into an interactive environment, as mentioned in the previous step. This means you cannot simply send the process to the background with something simple like &lt;code&gt;nohup&lt;/code&gt;, &lt;code&gt;&amp;amp;&lt;/code&gt;, or the combination of &lt;code&gt;ctrl+z&lt;/code&gt; and &lt;code&gt;bg&lt;/code&gt;. To send this kind of job to the background, we first have to create a file to mimic an input pipeline:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ mkfifo bridge_input
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, we launch Bridge in the background, but at the same time, we tell it that instead of using standard I/O, it has to read input from &lt;code&gt;bridge_input&lt;/code&gt; and write output to &lt;code&gt;bridge_output&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ nohup Desktop-Bridge --cli &amp;lt; &amp;lt;(tail -f bridge_input) &amp;amp;&amp;gt; bridge_log &amp;amp;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you do &lt;code&gt;$ cat bridge_log&lt;/code&gt;, you should see the welcome message from Bridge. And if you do &lt;code&gt;$ echo &quot;info&quot; &amp;gt;&amp;gt; bridge_input&lt;/code&gt; to issue an &lt;code&gt;info&lt;/code&gt; command to Bridge, and then do &lt;code&gt;$ cat bridge_log&lt;/code&gt;, you should see the output of &lt;code&gt;info&lt;/code&gt;. Finally, in some systems, you may have to run &lt;code&gt;$ disown&lt;/code&gt; to detach jobs from the current shell session, so that you can log out without terminating the jobs. To check that you indeed detached all jobs, use &lt;code&gt;$ jobs -l&lt;/code&gt;. If there is nothing in the output, then that means you are good to go. In the future when you want to stop Bridge, you can issue an &lt;code&gt;exit&lt;/code&gt; command through &lt;code&gt;$ echo &quot;exit&quot; &amp;gt;&amp;gt; bridge_input&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Step 3: (Optional) Test if Bridge in the background is working&lt;/h2&gt;
&lt;p&gt;An easy way to test whether Bridge is running in the background is to telnet to the fake local SMTP server:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ telnet 127.0.0.1 1025
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The IP &lt;code&gt;127.0.0.1&lt;/code&gt; and the port &lt;code&gt;1025&lt;/code&gt; can be found in the info output of Bridge, as mentioned in step 1. If Bridge is indeed running in the background, you should see the welcome message from the SMTP server. Then type &lt;code&gt;quit&lt;/code&gt; to exit the telnet session. Successfully connecting to the SMTP server with telnet does not mean you can also successfully send an email through it. But that is off the topic here, so I won&apos;t cover it. For those who are interested, please search for how to send a test email after connecting to SMTP via telnet. Here we simply assume that successfully connecting to the SMTP server means everything works fine.&lt;/p&gt;
&lt;h2&gt;Step 4: Set up SMTP server information in WordPress&lt;/h2&gt;
&lt;p&gt;In my case, I use the WP Mail SMTP plugin in WordPress. Back to the &lt;em&gt;abc@pm.me&lt;/em&gt; example mentioned in step 1, the Bridge info shows that we have to use:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Address: 127.0.0.1
SMTP port: 1025
Username: abc@pm.me
Password:

defghijklmnop!@#

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we have to fill out the setting page of the plugin as shown in the following picture:
&lt;a href=&quot;https://pychao.com/wp-content/uploads/2018/10/wp_bridge_setting.png&quot;&gt;&lt;img src=&quot;https://pychao.com/wp-content/uploads/2018/10/wp_bridge_setting.png&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Test if your WordPress server can send email from the test page as shown below:
&lt;a href=&quot;https://pychao.com/wp-content/uploads/2018/10/wp_bridge_setting_2.png&quot;&gt;&lt;img src=&quot;https://pychao.com/wp-content/uploads/2018/10/wp_bridge_setting_2.png&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you receive the test email at the destination address you provided, then congratulations. You are all set.&lt;/p&gt;
</content:encoded></item><item><title>Use ProtonMail Bridge on headless Linux machines</title><link>https://piyueh.github.io/posts/2018-10-13-use-protonmail-bridge-on-headless-linux-machines/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-10-13-use-protonmail-bridge-on-headless-linux-machines/</guid><pubDate>Sat, 13 Oct 2018 06:00:23 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Updates&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Jun. 10, 2020: I added a brief post about how to use &lt;code&gt;pass&lt;/code&gt; with ProtonMail Bridge for headless servers in a new post &lt;a href=&quot;https://pychao.com/2020/06/10/update-on-using-protonmail-bridge-on-headless-wordpress-linux-servers/&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Jan. 8, 2020: I recently found that the GUI-based &lt;code&gt;gnome-keyring&lt;/code&gt; can be replaced with a CLI-based password manager, &lt;code&gt;pass&lt;/code&gt;. I now use &lt;code&gt;pass&lt;/code&gt; instead of &lt;code&gt;gnome-keyring&lt;/code&gt;. &lt;s&gt;I haven&apos;t had time to update this post, so you&apos;ll have to do the research if you want to discard &lt;code&gt;gnome-keyring&lt;/code&gt;&lt;/s&gt;. A good place to start is the Arch Wiki page for &lt;code&gt;pass&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Aug. 7, 2019: The version of Bridge used in the original post was 1.0.6. I recently upgraded Bridge to 1.1.6 and found that the executable is no longer called &lt;code&gt;Desktop-Bridge&lt;/code&gt;. Now it&apos;s called &lt;code&gt;protonmail-bridge&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://protonmail.com/bridge/&quot;&gt;ProtonMail Bridge&lt;/a&gt; is the utility for ProtonMail users to access IMAP/SMTP servers from local machines. With ProtonMail Bridge, users can use whatever offline email client (Outlook, Thunderbird, etc.) they like. The reason ProtonMail users require this extra utility is that, for outbound emails, ProtonMail encrypts users&apos; email content before handing it over to the sending server. And for inbound emails, ProtonMail decrypts the email contents for users after downloading the emails, so when users open the incoming emails, the contents are readable. While using ProtonMail&apos;s online interface, everything is done behind the scenes. Users just write/read emails as they do on Gmail, etc. But if users want to use offline email clients on their local machines, then those clients lack the functionality to encrypt/decrypt the emails before/after communicating with ProtonMail&apos;s servers (see note 1). That&apos;s why ProtonMail provides a utility called Bridge. In a nutshell, ProtonMail Bridge creates fake IMAP/SMTP servers on the local machine. And users use these fake local servers for the IMAP/SMTP settings in their offline email clients. When offline clients try to communicate with email servers, they are in fact communicating with the fake local servers. Next, the local servers do the encryption/decryption tasks and then talk to the real ProtonMail servers. For more details, please read the introduction at &lt;a href=&quot;https://protonmail.com/bridge/&quot;&gt;ProtonMail Bridge&lt;/a&gt;. This post does not intend to deal with the usage of Bridge. Instead, this post tries to deal with an issue that occurs when using Bridge in headless (i.e., not connected to any physical monitors) Linux environments.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note 1: In fact, many offline email clients can handle PGP-encrypted emails. But when using ProtonMail, my guess is that ProtonMail servers do not allow client-side encryption and decryption, so they provide Bridge. But it&apos;s just my guess. I&apos;m also new to ProtonMail.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;Problem description&lt;/h2&gt;
&lt;p&gt;A dependency of Bridge is &lt;code&gt;gnome-keyring&lt;/code&gt; (note: see the update above). My guess is that Bridge relies on &lt;code&gt;gnome-keyring&lt;/code&gt; to store data and information on PGP keys. But the problem is that &lt;code&gt;gnome-keyring&lt;/code&gt; is not designed for headless environments. So when you try to launch non-graphical Bridge with &lt;code&gt;$ Desktop-Bridge --cli&lt;/code&gt; (note: see the update above), you may encounter problems when you log in with your ProtonMail account in Bridge.&lt;/p&gt;
&lt;h2&gt;Solution&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;gnome-keyring&lt;/code&gt; relies on a graphical pop-up dialog to ask users for passwords. So what we have to do is proactively provide our password when we start the keyring service in the background, instead of passively waiting for it to ask. Use the following command to achieve this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ echo -n [password] | gnome-keyring-daemon --login
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;[password]&lt;/code&gt; is your password to log in to the Linux machine. Even if you use password-less login (e.g., using SSH keys), you should have a password for your username. Note that &lt;code&gt;[password]&lt;/code&gt; should be a string. That is, your password should be inside a pair of quotation marks.&lt;/p&gt;
&lt;h2&gt;Reference&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://superuser.com/questions/141036/use-of-gnome-keyring-daemon-without-x&quot;&gt;use of gnome-keyring-daemon without X&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item><item><title>How to eliminate the link between diabetes and disability in late life?</title><link>https://piyueh.github.io/posts/2018-10-11-how-to-eliminate-the-link-between-diabetes-and-disability-in-late-life/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-10-11-how-to-eliminate-the-link-between-diabetes-and-disability-in-late-life/</guid><pubDate>Fri, 12 Oct 2018 01:23:52 GMT</pubDate><content:encoded>&lt;p&gt;Due to the growing aging population, non-pharmacological interventions to prevent diabetes-related disability are critical if we want to reduce costly healthcare use and excess mortality. When reviewing existing preventive interventions, there are two things that need to be kept in mind.&lt;/p&gt;
&lt;p&gt;First, only limited interventions have been developed to prevent disability among older adults with diabetes.&amp;lt;sup&amp;gt;6-8&amp;lt;/sup&amp;gt; Several systematic reviews have shown that these interventions mostly focus on lifestyle interventions (physical activity and a healthy diet) and self-management interventions to promote metabolic control.&amp;lt;sup&amp;gt;9-10&amp;lt;/sup&amp;gt; However, poor glycemic control is not necessarily associated with disability in older adults with diabetes.&amp;lt;sup&amp;gt;1,3&amp;lt;/sup&amp;gt;&lt;/p&gt;
&lt;p&gt;Second, even though lifestyle interventions are widely acknowledged to promote muscle strength, physical function, and reduce premature disability in older adults,&amp;lt;sup&amp;gt;11&amp;lt;/sup&amp;gt; little evidence supports the claim that lifestyle interventions may actually prevent disability. Keysor, Lorig, and Simonsick et al. all found that the benefits of physical activity in preventing disability are still poorly understood in late life.&amp;lt;sup&amp;gt;4,11,12&amp;lt;/sup&amp;gt;&lt;/p&gt;
&lt;p&gt;This may be explained by three limitations in current lifestyle interventions. First, disability is less often chosen as a primary outcome in lifestyle interventions.&amp;lt;sup&amp;gt;5&amp;lt;/sup&amp;gt; Second, it is widely believed that managing physical activity, healthy diet, and medication can transfer and generalize to promote other daily activities and thereby prevent disability.&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt; However, we still need more evidence to confirm whether improved physical function actually prevents or delays disability in late life.&lt;/p&gt;
&lt;p&gt;One may suggest that physical activity interventions can prevent mobility disability in late life. However, disability has been considered an umbrella concept that includes mobility disability (walking, climbing, or standing), ADL disability (eating and dressing), and IADL disability (shopping, driving, or preparing meals).&amp;lt;sup&amp;gt;2,13-15&amp;lt;/sup&amp;gt; We therefore need to understand whether physical activity programs not only prevent mobility disability but also prevent ADL and IADL disability.&lt;/p&gt;
&lt;p&gt;Third, some lifestyle interventions have successfully engaged older adults in exercise and healthy diets. But supporting continued engagement in physical activity and healthy diets is critical if we want to prevent disability in the long term.&lt;/p&gt;
&lt;p&gt;After discussing the current gaps in interventions for preventing disability among older adults with diabetes, one may ask: what are the next steps for future research? In fact, there are three steps to consider when thinking about preventing disability in older adults with diabetes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Define and decide what kind of disability you want to prevent&lt;/strong&gt;. Older adults with diabetes reported different types of disability (mobility; ADL; IADL) in daily lives.&amp;lt;sup&amp;gt;1,2,16,17&amp;lt;/sup&amp;gt; For example, Maty et al. found that among 3570 non-institutionalized female older adults with diabetes, 51% of them have difficulties walking 2-3 blocks, 31% of them had difficulties shopping, and 30% of them had difficulties bathing and showing.&amp;lt;sup&amp;gt;17&amp;lt;/sup&amp;gt; If one wants to prevent disability for older adults with diabetes, strategies should target on preventing mobility, ADL, and IADL disability.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consider the type of prevention you are going to apply&lt;/strong&gt;. Since older adults with diabetes are at high risk of developing risk factors of disability (depressive symptoms; cognitive impairment), one should apply the concept of indicative prevention: older adults who are experiencing early signs of disability or other risk factors associated with disability and treat them with special programs to reduce the risk factors.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Identify specific active ingredients to maintain the effects of interventions&lt;/strong&gt;. A systematic review of active ingredients in interventions had found that non-pharmacological interventions focused on behavioral changes rarely specified techniques to maintain the effects of interventions. Research has found that older adults with diabetes who maintained engagement in social activities had a better survival rate over a 2 year period.&amp;lt;sup&amp;gt;18&amp;lt;/sup&amp;gt; When one is developing interventions to prevent disability, there is a need to identify active ingredients for both initiating and continuing engagement of daily activities for older adults with diabetes.&amp;lt;sup&amp;gt;19&amp;lt;/sup&amp;gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Diabetes-related disability is a problem that reduces older adults’ quality of life and health. Preventing disability among older adults with diabetes is important because it may reduce substantial healthcare costs in late life.&lt;/p&gt;
&lt;p&gt;Because many medical, psychological, and social factors increase the risk of disability in older adults with diabetes, interventions that focus on diabetes diagnoses alone are not sufficient to explain the heterogeneity of disability in late life.&amp;lt;sup&amp;gt;20&amp;lt;/sup&amp;gt; Medical management by itself is not sufficient to prevent disability.&lt;/p&gt;
&lt;p&gt;Future interventions that aim to prevent disability should be individualized and tailored to older adults’ unique medical, psychological, and social situations. Indicated-prevention interventions should include strategies that address the interactions between risk factors, such as depressive symptoms and cognitive impairment, and disability in older adults with diabetes.&lt;/p&gt;
&lt;p&gt;Without considering the active ingredients that address social and environmental factors, preventing disability in late life is much less likely to happen.&lt;/p&gt;
&lt;h5&gt;References&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;Kalyani RR, Saudek CD, Brancati FL, Selvin E. Association of diabetes, comorbidities, and A1C with functional disability in older adults: Results from the National Health and Nutrition Examination Survey (NHANES), 1999-2006. &lt;em&gt;Diabetes Care&lt;/em&gt;. 2010;33(5):1055-1060.&lt;/li&gt;
&lt;li&gt;Wong E, Backholer K, Gearon E, et al. Diabetes and risk of physical disability in adults: A systematic review and meta-analysis. &lt;em&gt;Lancet Diabetes Endocrinol&lt;/em&gt;. 2013;1(2):106-114Bruce DG, Davis WA, Davis TME. Longitudinal predictors of reduced mobility and physical disability in patients with type 2 diabetes. &lt;em&gt;Diabetes Care&lt;/em&gt;. 2005;28(10).&lt;/li&gt;
&lt;li&gt;Bruce DG, Davis WA, Davis TME. Longitudinal predictors of reduced mobility and physical disability in patients with type 2 diabetes. &lt;em&gt;Diabetes Care&lt;/em&gt;. 2005;28(10).&lt;/li&gt;
&lt;li&gt;Simonsick EM, Guralnik JM, Volpato S, Balfour J, Fried LP. Just get out the door! Importance of walking outside the home for maintaining mobility: Findings from the women’s health and aging study. &lt;em&gt;J Am Geriatr Soc&lt;/em&gt;. 2005;53(2):198-203.&lt;/li&gt;
&lt;li&gt;Stewart A, Guralnik JM, Balfour J, Fried LP, deLateur BJ, Schwartz RS. Conceptual challenges in linking physical activity and disability research. &lt;em&gt;Am J Prev Med&lt;/em&gt;. 2003;25(3):137-140.&lt;/li&gt;
&lt;li&gt;Gregg EW, Caspersen CJ. Review: Physical disability and the cumulative impact of diabetes in older adults. &lt;em&gt;Br J Diabetes Vasc Dis&lt;/em&gt;. 2005;5(1):13-17.&lt;/li&gt;
&lt;li&gt;Gregg EW, Boyle JP, Thompson TJ, Barker LE, Albright AL, Williamson DF. Modeling the impact of prevention policies on future diabetes prevalence in the United States: 2010–2030. &lt;em&gt;Popul Health Metr&lt;/em&gt;. 2013;11.&lt;/li&gt;
&lt;li&gt;Gregg EW, Brown A. Cognitive and physical disabilities and aging-related complications of diabetes. &lt;em&gt;Clin Diabetes&lt;/em&gt;. 2003;21(3).&lt;/li&gt;
&lt;li&gt;Norris SL, Engelgau MM, Narayan KM. Effectiveness of self-management training in type 2 diabetes: A systematic review of randomized controlled trials. &lt;em&gt;Diabetes Care&lt;/em&gt;. 2001;24(3):561-587.&lt;/li&gt;
&lt;li&gt;Schellenberg ES, Dryden DM, Vandermeer B, Ha C, Korownyk C. Lifestyle interventions for patients with and at risk for type 2 diabetes. &lt;em&gt;Ann Intern Med&lt;/em&gt;. 2013;159(8):543.&lt;/li&gt;
&lt;li&gt;Keysor JJ, Jette AM. Have We oversold the benefit of late-life exercise? &lt;em&gt;Journals Gerontol Ser A Biol Sci Med Sci&lt;/em&gt;. 2001;56(7):M412-M423.&lt;/li&gt;
&lt;li&gt;Lorig KR, Holman HR. Self-management education: History, definition, outcomes, and mechanisms. &lt;em&gt;Ann Behav Med&lt;/em&gt;. 2003;26(1):1-7.&lt;/li&gt;
&lt;li&gt;Cigolle CT, Langa KM, Kabeto MU, Tian Z, Blaum CS. Geriatric conditions and disability: The health and retirement study. &lt;em&gt;Ann Intern Med&lt;/em&gt;. 2007;147(3):156.&lt;/li&gt;
&lt;li&gt;Murtagh KN, Hubert HB. Gender differences in physical disability among an elderly cohort. &lt;em&gt;Am J Public Health&lt;/em&gt;. 2004;94(8):1406-1411.&lt;/li&gt;
&lt;li&gt;Wray LA, Blaum CS. Explaining the role of sex on disability: A population-based study. &lt;em&gt;Gerontologist&lt;/em&gt;. 2001;41(4):499-510.&lt;/li&gt;
&lt;li&gt;Wu JH, Haan MN, Liang J, Ghosh D, Gonzalez HM, Herman WH. Diabetes as a predictor of change in functional status among older Mexican Americans: A population-based cohort study. &lt;em&gt;Diabetes Care&lt;/em&gt;. 2003;26(2):314-319.&lt;/li&gt;
&lt;li&gt;Maty SC, Fried LP, Volpato S, Williamson J, Brancati FL, Blaum CS. Patterns of disability related to diabetes mellitus in older women. &lt;em&gt;J Gerontol A Biol Sci Med Sci&lt;/em&gt;. 2004;59(2):148-153.&lt;/li&gt;
&lt;li&gt;Kuo Y-F, Raji MA, Peek MK, Goodwin JS. Health-related social disengagement in elderly diabetic patients. &lt;em&gt;Diabetes Care&lt;/em&gt;. 2004;27(7).&lt;/li&gt;
&lt;li&gt;Greaves CJ, Sheppard KE, Abraham C, et al. Systematic review of reviews of intervention components associated with increased effectiveness in dietary and physical activity interventions. &lt;em&gt;BMC Public Health&lt;/em&gt;. 2011;11(1):119.&lt;/li&gt;
&lt;li&gt;Leveille SG, Fried L, Guralnik JM. Disabling symptoms: What do older women report?. &lt;em&gt;J Gen Intern Med&lt;/em&gt;. 2002;17(10):766-773.&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item><item><title>Modernism, Postmodernism and the Development of Disability Models</title><link>https://piyueh.github.io/posts/2018-10-09-modernism-postmodernism-and-the-development-of-disability-models/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-10-09-modernism-postmodernism-and-the-development-of-disability-models/</guid><pubDate>Wed, 10 Oct 2018 01:14:36 GMT</pubDate><content:encoded>&lt;p&gt;Modernism and Postmodernism, which began in the late 1950s and the mid-1970s, have influenced the development of disability models. In this post, I introduce the similarities and differences between disability models in the late 20th century and explain how rehabilitation sciences mirror Modernism and Postmodernism.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Modernism and Postmodernism&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Modernism began after World War II and gradually transformed into Postmodernism in the mid-1970s. Modernism arose from the Theory of General Relativity proposed by Albert Einstein. The formulas in the Theory of General Relativity provide a unified description of gravity as a geometric property of space and time (Synge, J. L., 1960). After Einstein published the Theory of General Relativity, society started to embrace “universalism” and believe that “truth” exists only in facts.&lt;/p&gt;
&lt;p&gt;The limitations of Modernism led to the development of Postmodernism. Postmodernism, in contrast to Modernism, favors pluralism, particularism, and diversity. Postmodernism places emphasis on subjective experience and the empowerment of human beings (Moxley, D. P., 1995).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The development of disability models follows a similar trajectory&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There is a similar trajectory in the development of disability models. The Nagi model, which is thought to be the first disability model, originated in 1965 (Altman, B. M., 2001). The Nagi model is a typical disease model that defined pathology as an interruption in “normal” body processes. The author built the Nagi model with dualist terms, such as normal and abnormal.&lt;/p&gt;
&lt;p&gt;In 1980, the International Classification of Impairments, Disabilities and Handicaps (ICIDH) model proposed that disability is the result of an “abnormality” of body structure and function (Johnston, M., &amp;amp; Pollard, B., 2001). Researchers have critiqued the Nagi and ICIDH models for their focus on diseases and for their blurred definitions of “normality.”&lt;/p&gt;
&lt;p&gt;In the early 21st century, the International Classification of Functioning, Disability, and Health (ICF) was developed to provide a framework and a unified taxonomy in the health sciences. In the ICF, we no longer see the “normality” concept. Instead, there are complex mechanisms and terms used in the framework, such as the six interrelated concepts in the ICF.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Modernism, Postmodernism, and disability models in rehabilitation sciences&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;From the Nagi model to the ICF, the way disability was defined changed from linear to multidirectional, from dichotomous to a spectrum, and from dualist to pluralist. This change echoes the shift from Modernism to Postmodernism.&lt;/p&gt;
&lt;p&gt;Modernism views a person as an object, thus treating disability as a disease that needs to be cured and normalized. Postmodernism views a person from many perspectives, including economic, social, political, and historical status. The most popular disability framework, the ICF, employs the spirit of Postmodernism. But to some degree, it still uses Modernist principles.&lt;/p&gt;
&lt;p&gt;The ICF tries to present the dynamics of subjective behaviors and experiences, and its decentralization equally emphasizes all the concepts. Nevertheless, the systematic coding scheme used in the ICF and its intention to develop a unified taxonomy still show dualism and universalism, which are Modernist perspectives.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Future suggestions&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;From the development of disability models, we can see the evolution of thinking in rehabilitation sciences. However, there are a few questions that still need to be answered.&lt;/p&gt;
&lt;p&gt;First, the nature of pluralism makes it harder to reach a consensus on disability models. With the growth of integrated models, is it necessary to use a specific model as a guiding principle? How do we decide which disability model should be followed by legislators and stakeholders?&lt;/p&gt;
&lt;p&gt;Second, disability models are influenced by historical progress and people&apos;s beliefs. How can we think independently in order to refine the definition of disability? Could we build a disability model that combines the advantages of both Modernism and Postmodernism?&lt;/p&gt;
&lt;p&gt;Third, from the Nagi model to the ICF, scholars still use unified terminology and apply a dualist principle to explain disability. While we put too much emphasis on terminology and definitions in disability models, do we leave enough room for diversity and evolution?&lt;/p&gt;
&lt;h6&gt;Reference&lt;/h6&gt;
&lt;h6&gt;Altman, B. M. (2001). Disability definitions, models, classification schemes, and applications. Handbook of disability studies, 97-122.&lt;/h6&gt;
&lt;h6&gt;Garland-Thomson, R. (2002). Integrating disability, transforming feminist theory. NWSA Journal, 14(3), 1-32.&lt;/h6&gt;
&lt;h6&gt;Johnston, M., &amp;amp; Pollard, B. (2001). Consequences of disease: testing the WHO International Classification of Impairments, Disabilities and Handicaps (ICIDH) model. Social Science &amp;amp; Medicine, 53(10), 1261-1273.&lt;/h6&gt;
</content:encoded></item><item><title>Accessing an SSH server that is behind a VPN</title><link>https://piyueh.github.io/posts/2018-08-07-accessing-a-ssh-server-that-is-behind-a-vpn/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-08-07-accessing-a-ssh-server-that-is-behind-a-vpn/</guid><pubDate>Tue, 07 Aug 2018 08:14:00 GMT</pubDate><content:encoded>&lt;p&gt;If you own an SSH server and that machine is behind a VPN, then without any special setup you are not able to SSH to it with its original public IP from a client outside the VPN. An easy solution is to disconnect the machine from the VPN so clients outside the VPN can access it. But what if you really want to keep using the VPN on that machine?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Disclaimer: I am no expert, so I am not confident that all the procedures I used or all of my understanding are correct. What I am sure of is only that it works on my machine. That is to say, if you want to try my solution, please use caution. Also, any correction is welcome. I hope to learn from real experts.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The underlying issue of an SSH server behind a VPN is that when a client connects to a server with the server&apos;s public IP, the client expects to receive the server&apos;s return traffic from the same public IP. But the server is behind a VPN. In other words, when the server tries to return SSH traffic, it uses the VPN. Then the client receives the return traffic from the VPN&apos;s IP, not the server&apos;s original public IP that it is expecting. So the client rejects the packets and drops the SSH connection.&lt;/p&gt;
&lt;p&gt;The idea of the solution is to route the server&apos;s return SSH traffic through its original IP. And this routing is allowed only when the server is responding to traffic coming to the original IP, not to other IPs (i.e., not to traffic coming to the VPN&apos;s IP).&lt;/p&gt;
&lt;h2&gt;Step 1: obtain subnet and mask information&lt;/h2&gt;
&lt;p&gt;There are many ways to do this. Here is a beginner&apos;s approach. If you are using NetworkManager, then find the &lt;code&gt;inet4&lt;/code&gt; information in the output of the &lt;code&gt;nmcli&lt;/code&gt; command. For example, the output may look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ nmcli
--------------------------------------------------------
ch-us-01.protonvpn.com.udp1194 VPN connection
        *content hidden*

docker0: connected to docker0
        *content hidden*

enp8s0: connected to Wired connection 1
        &quot;Intel I211&quot;
        ethernet (igb), xx:xx:xx:xx:xx:xx, hw, mtu 1500
        **inet4 123.123.123.123/23**
        route4 0.0.0.0/0
        route4 x.x.x.x/24

tun0: connected to tun0
        *content hidden*

eno1: unavailable
        *content hidden*

lo: unmanaged
        *content hidden*

DNS configuration:
        *content hidden*
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The interface &lt;code&gt;enp8s0&lt;/code&gt; is the one connecting to the internet in this example. And the line &lt;code&gt;inet4 123.123.123.123/23&lt;/code&gt; gives the public IPv4 address and the mask. If you don&apos;t know how to calculate the subnet, use any IP calculator on the internet. For example, if you use &lt;a href=&quot;http://jodies.de/ipcalc&quot;&gt;this calculator&lt;/a&gt; with the IP address &lt;code&gt;123.123.123.123&lt;/code&gt; and the mask &lt;code&gt;23&lt;/code&gt;, the line &lt;code&gt;Network:   123.123.122.0/23&lt;/code&gt; in the output represents the subnet and the mask.&lt;/p&gt;
&lt;h2&gt;Step 2: obtain gateway information&lt;/h2&gt;
&lt;p&gt;Next, we need the gateway address. The following command outputs the routes related to the internet interface &lt;code&gt;[INTERFACE]&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ ip route show dev [INTERFACE]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, let&apos;s use the previous example, in which &lt;code&gt;enp8s0&lt;/code&gt; is the name of the interface. The output may look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ ip route show dev enp8s0
------------------------------------------------------------------------
default via 123.123.123.254 proto dhcp metric 100 
123.123.122.0/23 proto kernel scope link src 123.123.123.123 metric 100 
123.123.123.123 proto static scope link metric 100 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The IP &lt;code&gt;123.123.123.254&lt;/code&gt; in the line &lt;code&gt;default via ...&lt;/code&gt; is the gateway.&lt;/p&gt;
&lt;h2&gt;Step 3: add a routing table and rules&lt;/h2&gt;
&lt;p&gt;First, we add a table for traffic coming to the original public IP and name the table &lt;code&gt;128&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# ip rule add from [PUBLIC IP] table 128
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To my understanding, the above command says that whenever there is traffic coming to the public IP, the system will look up the routing rules in table &lt;code&gt;128&lt;/code&gt;. Next, we add routing rules to that table:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# ip route add table 128 to [SUBNET]/[MASK] dev [INTERFACE]
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;# ip route add table 128 default via [GATEWAY]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To be honest, I don&apos;t really know what these two commands are doing. I have almost zero knowledge of networking. I don&apos;t even really know what subnet and gateway mean in detail. I hope someone can help me understand them better.&lt;/p&gt;
&lt;p&gt;But what I do know is that after this step, when there is traffic coming to the public IP, the machine will accept it. And if the machine has to respond to that traffic, it will use the default IP instead of the VPN. But the problem is that we may not want connections other than SSH to go through the public IP. So we have to block other connections with a firewall.&lt;/p&gt;
&lt;h2&gt;Step 4: allow firewall to only accept SSH traffic coming to the original public IP&lt;/h2&gt;
&lt;p&gt;In this example, I use &lt;code&gt;iptables&lt;/code&gt; to control the kernel-level Linux firewall directly. I think other user-friendly interfaces should also work if you have one. When there is traffic coming to the original public IP and to the SSH server&apos;s listening port, we want the system to accept it.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# iptables -A INPUT -d [PUBLIC IP] -p tcp --dport [SSH LISTENING PORT] -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And for all other traffic coming to the original public IP, but not to the SSH server&apos;s port, we want the machine to drop it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# iptables -A INPUT -d [PUBLIC IP] -j DROP
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now clients outside the VPN should be able to SSH to the machine while the machine is still using the VPN.&lt;/p&gt;
</content:encoded></item><item><title>How to get the number of inotify watches used by a process</title><link>https://piyueh.github.io/posts/2018-03-22-how-to-get-the-number-of-inotify-watches-used-by-a-process/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-03-22-how-to-get-the-number-of-inotify-watches-used-by-a-process/</guid><pubDate>Thu, 22 Mar 2018 19:27:23 GMT</pubDate><content:encoded>&lt;p&gt;Recently, &lt;em&gt;PulseAudio&lt;/em&gt; often refused to start because the system ran out of &lt;em&gt;inotify&lt;/em&gt; watches. I tried to Google this issue and found that most posts simply told me to increase the allowance of inotify watches. I was not satisfied with this. I wanted to know the underlying cause of this issue. That is, why the default allowance (which is 8192) was not enough and, also, what program was responsible for running out of &lt;em&gt;inotify&lt;/em&gt; watches. Knowing this information, I may be able to find a better solution, instead of blindly increasing the allowance without knowing who is using it. After googling, I found some posts talking about how to know what processes/programs are using &lt;em&gt;inotify&lt;/em&gt;. But I could hardly find posts about how to know &lt;em&gt;HOW MANY INOTIFY WATCHES ARE USED BY EACH OF THOSE PROCESSES/PROGRAMS&lt;/em&gt;. I finally found one in &lt;a href=&quot;https://unix.stackexchange.com/a/426001&quot;&gt;a reply in this thread&lt;/a&gt;. The author of that reply spent a lot of words explaining the idea behind his/her solution. I re-organized the information, eliminated those explanations, and kept only the method. By this method, I finally found out who is responsible for running out of &lt;em&gt;inotify&lt;/em&gt; watches: &lt;em&gt;Insync&lt;/em&gt;. I got over 50K files in the sync folder of &lt;em&gt;Insync&lt;/em&gt;, and so Insync used over 12.5K watches, which exceeds the default allowance, 8192.&lt;/p&gt;
&lt;h3&gt;Step 1: Find what processes/programs are using &lt;em&gt;inotify&lt;/em&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;$ sudo find /proc/*/fd -lname anon_inode:inotify | cut -d/ -f3 | xargs -I &apos;{}&apos; -- ps --no-headers -o &apos;%p %U %c&apos; -p &apos;{}&apos; | uniq -c | sort -nr
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the output, each row represents a process/program using &lt;em&gt;inotify&lt;/em&gt;. The first column is the number of &lt;em&gt;inotify&lt;/em&gt; &quot;instances&quot; created by that program. The second column is the PID. And the third and the fourth are the user and the name of that program, respectively. Note that it is the number of &quot;instances&quot;, not the number of &quot;watches&quot;.&lt;/p&gt;
&lt;h3&gt;Step 2: Find the file descriptor of &lt;em&gt;inotify&lt;/em&gt; instances&lt;/h3&gt;
&lt;p&gt;Now we pick a program we found, and then we want to know how many &quot;watches&quot; the program uses. But first we need to know the file descriptor of the &quot;instances&quot; created by this program:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ sudo ls -athlr /proc/&amp;lt;PID&amp;gt;/fd | grep anon_inode:inotify
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The number of rows in the output should match the number of &quot;instances&quot; created by that program. The file descriptor is the number before &lt;code&gt;-&amp;gt; anon_inode:inotify&lt;/code&gt; in each line. For example, in &lt;code&gt;lr-x------ 1 &amp;lt;user&amp;gt; &amp;lt;group&amp;gt; 64 Mar 21 23:24 19 -&amp;gt; anon_inode:inotify&lt;/code&gt;, the file descriptor for this inotify instance is &lt;code&gt;19&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Step 3: Get the number of watches in each instance&lt;/h3&gt;
&lt;p&gt;After we have the file descriptor of each instance created by our target program, we can calculate the number of watches in that instance by:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ sudo wc -l /proc/&amp;lt;PID&amp;gt;/fdinfo/&amp;lt;file descriptor&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first column in the output is the number we are looking for. This is just the number for one instance of a program. To know the total watches of a program, we also have to check the other instances.&lt;/p&gt;
&lt;h3&gt;A fake example&lt;/h3&gt;
&lt;p&gt;Here&apos;s a fake example to give a sense.&lt;/p&gt;
&lt;p&gt;Step 1:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ sudo find /proc/*/fd -lname anon_inode:inotify | cut -d/ -f3 | xargs -I &apos;{}&apos; -- ps --no-headers -o &apos;%p %U %c&apos; -p &apos;{}&apos; | uniq -c | sort -nr
--------------------------------------------------------------------
5        6679     root     systemd
3        7878     user     chrome
1        12345    user     termite
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Step 2: Let&apos;s say we want to know the number of watches used by Chrome.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ sudo ls -athlr /proc/7878/fd | grep anon_inode:inotify
---------------------------------------------------
lr-x------ 1 user user 64 Mar 21 23:24 5 -&amp;gt; anon_inode:inotify
lr-x------ 1 user user 64 Mar 21 23:24 18 -&amp;gt; anon_inode:inotify
lr-x------ 1 user user 64 Mar 21 23:24 19 -&amp;gt; anon_inode:inotify
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Step 3:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ sudo wc -l /proc/7878/fdinfo/5
---------------------------------------------
2        /proc/565/fdinfo/5
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;$ sudo wc -l /proc/7878/fdinfo/18
---------------------------------------------
5        /proc/565/fdinfo/18
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;$ sudo wc -l /proc/7878/fdinfo/19
---------------------------------------------
1        /proc/565/fdinfo/19
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, the total number of watches used by Chrome is &lt;code&gt;2+3+1=6&lt;/code&gt;.&lt;/p&gt;
</content:encoded></item><item><title>Turn an Acer Chromebook 14 (CB3-431) to an Arch Linux laptop</title><link>https://piyueh.github.io/posts/2018-03-18-turn-an-acer-chromebook-14-cb3-431-to-an-arch-linux-laptop/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-03-18-turn-an-acer-chromebook-14-cb3-431-to-an-arch-linux-laptop/</guid><pubDate>Sun, 18 Mar 2018 21:40:26 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;Updates&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;08/15/2020: The CB3-431 described in this post is the one released around 2016. Acer is still selling Chromebooks under model code CB3-431. But I&apos;m not sure if the one Acer is selling now is the same as the one in this post.&lt;/li&gt;
&lt;li&gt;10/11/2018: It seems the current official &lt;code&gt;linux&lt;/code&gt; kernel (4.18.12-arch1-1) works fine now. Now I always boot into the official kernel instead of the &lt;code&gt;linux-galliumos&lt;/code&gt; kernel. And I haven&apos;t encountered any problem so far.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Get tired of using &lt;a href=&quot;https://github.com/dnschneid/crouton&quot;&gt;Crouton&lt;/a&gt; and &lt;code&gt;chroot&lt;/code&gt;? Can&apos;t stand Ubuntu and low-performance and fake X windows anymore? Try turning your Acer Chromebook 14 (CB3-431) into an Arch Linux machine. This post collects the required information from the internet and describes a procedure that worked on my machine. The majority of the procedure comes from Arch Linux&apos;s wiki:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://wiki.archlinux.org/index.php/Acer_Chromebook_14_CB3-431_(Edgar)&quot;&gt;Acer Chromebook 14 CB3-431 (Edgar)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://wiki.archlinux.org/index.php/Chrome_OS_devices&quot;&gt;Chrome OS devices&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Though the information in the wiki pages is out of date to some degree, they are still good references.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;An external keyboard is required because the internal one does not work out of the box at the beginning. Either a USB keyboard or a wireless one with a dongle works. A Bluetooth keyboard, however, may not work.&lt;/li&gt;
&lt;li&gt;I use Arch Linux only, so I chose the UEFI way and completely wiped out Chrome OS. For dual booting, those who are interested may need to do their own googling and cannot simply follow this post.&lt;/li&gt;
&lt;li&gt;Prepare a bootable Arch Linux installation USB stick in advance. The one I am using is the &lt;em&gt;2018.03.01&lt;/em&gt; release, which has kernel v4.14.6.&lt;/li&gt;
&lt;li&gt;A knowledge of how to do regular Arch Linux installation on regular laptops and desktops is required because I am not going to explain that here.&lt;/li&gt;
&lt;li&gt;I am no computer engineer nor OS engineer, so many technical terms may not be correct in this post. Corrections are welcome.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Disclaimer: The procedure described in this post includes practices that are not encouraged by Acer. It also uses an executable shell script from a third-party organization. So please be aware of the risk involved. If your Chromebook turns into a brick, I am not going to be responsible for that.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;1. Turn the hard write-protection off&lt;/h2&gt;
&lt;p&gt;This needs small-size screwdrivers.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Loosen the screws on the back of the machine and remove the back panel.&lt;/li&gt;
&lt;li&gt;There is a screw at the center after removing the back panel. This screw is obviously larger than others and is next to a black ribbon cable. Remove it. (Keep the screw properly in case you want to re-enable the hard write-protection in the future.)&lt;/li&gt;
&lt;li&gt;Put the back panel back.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For more details, see &lt;a href=&quot;https://www.ifixit.com/Teardown/Acer+Chromebook+14+Teardown/76353#s153416&quot;&gt;this instruction&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;2. Turn the soft write-protection off&lt;/h2&gt;
&lt;p&gt;See &lt;a href=&quot;https://wiki.archlinux.org/index.php/Chrome_OS_devices#Installation&quot;&gt;this&lt;/a&gt; for more details. I believe most readers of this post have already been using the developer mode for some reasons and know what these are. The following is a brief procedure:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enable the developer mode.&lt;/li&gt;
&lt;li&gt;Log in to a superuser shell.&lt;/li&gt;
&lt;li&gt;Disable the soft write-protection: &lt;code&gt;# flashrom --wp-disable&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;3. Use &lt;a href=&quot;https://mrchromebox.tech/#fwscript&quot;&gt;MrChromebox&apos;s firmware utility script&lt;/a&gt; to install full UEFI firmware.&lt;/h2&gt;
&lt;p&gt;In a superuser shell, run the shell script. After getting into the main menu, first select option &lt;strong&gt;4: Set Boot Options&lt;/strong&gt;. And in the child menu, select &lt;strong&gt;1&lt;/strong&gt;. This allows the system to go directly into the boot menu without you pressing any key (such as &lt;code&gt;ctrl+l&lt;/code&gt;). Next, when back in the main menu, select option &lt;strong&gt;3: Install/Update Full ROM Firmware&lt;/strong&gt;. Making a backup of original stock firmware is optional.&lt;/p&gt;
&lt;h2&gt;4. Reboot and install Arch Linux as usual&lt;/h2&gt;
&lt;p&gt;Insert the Arch Linux USB and the external keyboard, and then reboot. The machine should directly go to the bootloader of the bootable Arch Linux USB. From this point, Arch Linux can be installed as usual. Nothing is different from a regular installation. However, do make sure that UEFI mode is in use. Regarding the bootloader, I am using &lt;a href=&quot;https://wiki.archlinux.org/index.php/Systemd-boot&quot;&gt;&lt;code&gt;systemd-boot&lt;/code&gt;&lt;/a&gt;. Grub is more popular among those who install Linux on a Chromebook.&lt;/p&gt;
&lt;h2&gt;5. Replace the original Linux kernel with the one from Gallium OS (note: see Update 1)&lt;/h2&gt;
&lt;p&gt;After installation, install &lt;a href=&quot;https://aur.archlinux.org/pkgbase/linux-galliumos/&quot;&gt;&lt;code&gt;linux-galliumos&lt;/code&gt;&lt;/a&gt; from AUR. Remember to let the bootloader boot into Gallium OS&apos;s kernel afterward, instead of the original one. For example, if using &lt;code&gt;systemd-boot&lt;/code&gt;, either create a new boot entry or modify an old one with the following option: &lt;code&gt;linux /vmlinuz-linux-galliumos&lt;/code&gt;. Some notes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Avoid using &lt;code&gt;yaourt&lt;/code&gt; or similar utilities to automatically build and install &lt;code&gt;linux-galliumos&lt;/code&gt;. At least not with the default configuration of these utilities. With &lt;code&gt;yaourt&lt;/code&gt; and default configuration, for example, it will try to download and build the package in &lt;code&gt;/tmp&lt;/code&gt;, which consumes the memory. However, there is only about 4GB of memory on CB3-431, so using &lt;code&gt;yaourt&lt;/code&gt; will run out of the memory and crash if there is no swap space. Even if with enough swap space, it&apos;s still not encouraged because things will get slowed down when swap is involved. The simplest solution is just to build the package manually at the places that are not using memory.&lt;/li&gt;
&lt;li&gt;To accelerate the building process of this package, it is better to build the package on other Arch Linux machines that have more CPU cores. And then copy the resulting &lt;code&gt;*.pkg.tar.xz&lt;/code&gt; tarball back and install it. Don&apos;t forget to set the &lt;code&gt;MAKEFLAGS&lt;/code&gt; variable in &lt;code&gt;/etc/makepkg.conf&lt;/code&gt; to use more cores, and remember not to use any machine specific optimization compilation flags.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As for the original kernel, it is optional to keep them. I am not sure when the official kernel will support Braswell architecture. I do not even know if this support is on the schedule. After booting with Gallium OS&apos;s kernel, the internal keyboard should work out of the box.&lt;/p&gt;
&lt;h2&gt;6. Fix sound with Gallium OS patches&lt;/h2&gt;
&lt;p&gt;Install PulseAudio as usual. And then install &lt;a href=&quot;https://aur.archlinux.org/packages/galliumos-braswell-config/&quot;&gt;galliumos-braswell-config&lt;/a&gt; from AUR. The &lt;code&gt;--force&lt;/code&gt; flag may be required in the &lt;code&gt;pacman&lt;/code&gt; command to overwrite some files owned by PulseAudio. Because &lt;code&gt;galliumos-braswell-config&lt;/code&gt; overwrites some files also owned by PulseAudio, when upgrading system packages in the future, &lt;code&gt;pacman&lt;/code&gt; may complain that some files are owned by both packages. I believe this complaint is normal because it is true.&lt;/p&gt;
&lt;h2&gt;7. Others&lt;/h2&gt;
&lt;p&gt;We are free to do anything we want from this point. However, do remember there is only about 32GB or even less space on the MMC disk of CB3-431, and about 4GB of memory. So choose what you are going to install wisely. Also, here are two extra settings that are not necessary:&lt;/p&gt;
&lt;h3&gt;6-1. Install &lt;a href=&quot;https://aur.archlinux.org/packages/xkeyboard-config-chromebook/&quot;&gt;xkeyboard-config-chromebook&lt;/a&gt; from AUR.&lt;/h3&gt;
&lt;p&gt;I am not sure how this changes the use of the internal keyboard. I just found it from Arch Linux&apos;s wiki page and thought it would not do any harm, so I installed it. But I did not feel any difference.&lt;/p&gt;
&lt;h3&gt;6-2. Touchpad&lt;/h3&gt;
&lt;p&gt;The touchpad works out of the box after using Gallium OS&apos;s kernel. The driver used by default is &lt;code&gt;libinput&lt;/code&gt;, and it works fine. I did not try &lt;code&gt;xf86-input-synaptics&lt;/code&gt;. I did two extra settings:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;As suggested by Arch Linux&apos;s wiki, I put some settings in &lt;code&gt;/etc/udev/hwdb.d/99-touchpad-pressure.hwdb&lt;/code&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;libinput:name:*Elan Touchpad:dmi:*svnGOOGLE:*pnEdgar*
 LIBINPUT_ATTR_PRESSURE_RANGE=1:15
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But to be honest, I do not know what this is doing.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;To have the same touchpad experience as in original Chrome OS, I have the following settings for the touchpad in X environments:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;cat /etc/X11/xorg.conf.d/30-touchpad.conf
---------------------------------------------------------
Section &quot;InputClass&quot;
    Identifier &quot;Elan Touchpad&quot;
    Driver &quot;libinput&quot;
    Option &quot;NaturalScrolling&quot; &quot;true&quot;
    Option &quot;Tapping&quot; &quot;true&quot;
    Option &quot;MiddleEmulation&quot; &quot;true&quot;
    Option &quot;TappingButtonMap&quot; &quot;lrm&quot;
    Option &quot;TappingDrag&quot; &quot;true&quot;
EndSection
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So the tapping and scrolling experience became the same as it was in the original Chrome OS.&lt;/p&gt;
</content:encoded></item><item><title>bbswitch fails to switch GPUs ON/OFF</title><link>https://piyueh.github.io/posts/2018-03-18-bbswitch-fails-to-switch-gpus-on-off/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-03-18-bbswitch-fails-to-switch-gpus-on-off/</guid><pubDate>Sun, 18 Mar 2018 18:21:29 GMT</pubDate><content:encoded>&lt;h2&gt;System info&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Machine: Lenovo W540 with NVIDIA K2100&lt;/li&gt;
&lt;li&gt;OS: Archlinux with kernel 4.18.1&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bbswitch&lt;/code&gt; version: 0.8-117&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following were my settings at the time when this issue happened. Kernel module &lt;code&gt;bbswitch&lt;/code&gt; was set to be automatically loaded:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ cat /etc/modules-load.d/bbswitch.conf
---------------------------------------
bbswitch
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;NVIDIA modules were put into the blacklist:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ cat /etc/modprobe.d/blacklist.conf
------------------------------------
blacklist nvidia
blacklist nvidia_drm
blacklist nvidia_modeset
install nvidia /bin/false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;bbswitch&lt;/code&gt; was set to turn off the GPU right after boot:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ cat /etc/modprobe.d/bbswitch.conf
-----------------------------------
options bbswitch load_state=0 unload_state=1
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Symptom&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;# tee /proc/acpi/bbswitch &amp;lt;&amp;lt;&amp;lt;OFF&lt;/code&gt; and &lt;code&gt;# tee /proc/acpi/bbswitch &amp;lt;&amp;lt;&amp;lt;ON&lt;/code&gt; wouldn&apos;t actually change the value in &lt;code&gt;/proc/acpi/bbswitch&lt;/code&gt;. From the output of &lt;code&gt;lspci -nk&lt;/code&gt; or &lt;code&gt;lsmod | grep nvidia&lt;/code&gt;, it seems that after boot &lt;code&gt;bbswitch&lt;/code&gt; was indeed loaded and NVIDIA modules were not. The GPU, however, was always on after boot. In other words, manually switching ON/OFF and automatically turning off the GPU were not working.&lt;/p&gt;
&lt;h2&gt;Solution&lt;/h2&gt;
&lt;p&gt;Add the following kernel parameters at boot:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;acpi_osi=&quot;!Windows 2013&quot; acpi_osi=Linux
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For more details, please refer to &lt;a href=&quot;https://github.com/Bumblebee-Project/Bumblebee/issues/592&quot;&gt;this discussion&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Reference&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/Bumblebee-Project/Bumblebee/issues/592&quot;&gt;Issue #592 @ Bumblebee&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content:encoded></item><item><title>Hello world!</title><link>https://piyueh.github.io/posts/2018-03-01-hello-world/</link><guid isPermaLink="true">https://piyueh.github.io/posts/2018-03-01-hello-world/</guid><pubDate>Thu, 01 Mar 2018 19:01:45 GMT</pubDate><content:encoded>&lt;p&gt;Hello, world! This is our first post. Don&apos;t be surprised if you find this to be also our last post in the future...&lt;/p&gt;
</content:encoded></item></channel></rss>