/images/avatar.png
Change Language 👉   

Polling Jupyter widget UI events in runtime

Let’s look at a code snippet in the Jupyter Notebook:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import time
import ipywidgets as widgets
from IPython.display import display

slider = widgets.IntSlider()
display(slider)

while True:
    print(slider.value)
    time.sleep(1)

IntSlider is an interactive Jupyter Notebook widget. When the user interacts with the slider, the slider value should change.

However, if you run the above codes, you will find that the printed value of the slider won’t change at all – it will be stuck at its initial value.

Python coroutines and asyncio

Recently, I have been using Python coroutines/asynchronous programming in a project. Now, I will summarize my experience.

Import

1
import asyncio

If asyncio is to be used in an IPython environment, we have to add two more lines:

1
2
3
import nest_asyncio
nest_asyncio.apply()
import asyncio

Coroutines

Coroutines are the core of asynchronous programming in Python. To define a coroutine, you need to use async def.

1
2
3
async def main():
    # do something
    print("Hello world!")

To execute the coroutine, you cannot directly call main(). Instead, you need to use run():

Access the Internet from evaluation boards via PC

Windows

Set a network adapter that can access the internet in the Control Panel and share it with Ethernet. The IP address of Ethernet will change to 192.168.137.1 (this is the default behavior in Windows).

Then, set the gateway as 192.168.137.1 in the terminal of the development board:

sudo route add default gw 192.168.137.1

Set the IP address as 192.168.137.x, where x is any value except 1 and 255 (gateway address and broadcast address):

Increasing the swapfile for Linux

Xilinx’s toolchain consumes soooo much memory! Sometimes it causes the system to freeze… After all, my laptop only has 8GB of RAM. So there’s no other choice but to add virtual memories.

After increase the swapfile, the system performance has improved a lot:

1
2
3
4
sudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1M count=16384
sudo mkswap /swapfile
sudo swapon /swapfile

Partitioning and formatting SD cards on Linux

To partition and format an SD card in Linux, follow these steps: First, connect the SD card to your PC. Then, use the fdisk command in the bash command line to partition the SD card. Finally, use the mkfs command to create a file system (format) on the SD card.

The main commands are as follows:

First, use sudo fdisk -l to confirm which device in /dev corresponds to the SD card.

Mounting the EFI partition in Windows OS

To mount the EFI partitions, run the following commands in PowerShell:

1
2
3
4
5
6
diskpart
list disk  # make sure which is the disk that contains the EFI partition. usually 0
select disk 0
list partition # make sure which is the EFI partition. normally 0
select disk 0
assign letter=z

Then we will mount the EFI partition as drive Z.

This operation may be useful when using a dual-boot system with Windows and Ubuntu: Sometimes, after removing the Ubuntu system, only the Windows system remains, but the GRUB interface still appears every time the computer boots. In this case, you need to delete the old Ubuntu EFI partition.

Curl in high dimensions

1 Differential Forms

Before introducing the concept of curl, we need to first introduce differential forms and the exterior derivative.

An n-form can be defined as an alternating multilinear mapping $\omega:(T_p^*M)^n\rightarrow \mathbb{R}$. It maps multiple vectors to a real number. Additionally, it satisfies the alternating property, meaning that exchanging two input vectors results in an output multiplied by a negative sign.

Therefore, an n-form can be explicitly defined as follows:

What on earth are the pseudovectors?

1 Introduction

In physics textbooks, we often come across the terms “pseudo-vector” and “pseudo-scalar.”

In fact, on a 3-dimensional manifold, a “pseudo-vector” is the exterior product of two tangent vectors, denoted as $v\in T_pM\wedge T_pM=\bigwedge^2(T_pM)$, while a “pseudo-scalar” is the exterior product of three tangent vectors, denoted as $s\in T_pM\wedge T_pM\wedge T_pM=\bigwedge^3(T_pM)$.

When equipped with an inner product (or non-degenerate bilinear form), there exists a Hodge duality between $\bigwedge^2(T_pM)$ and $\bigwedge^1(T_pM)$, which leads us to mistakenly consider the pseudo-vector as a vector. Similarly, due to the Hodge duality between $\bigwedge^3(T_pM)$ and $\bigwedge^0(T_pM)$ (scalar fields), we mistakenly treat the pseudo-scalar as a scalar.

Blog Migration

I recently discovered this fantastic tool for creating personal websites - Hugo. Feels really cool and user-friendly! Plan to gradually migrate my blogs from Zhihu to here in the future.