Posts by Collection

articles

Applications

5 minute read

Now we have all the tools. Let’s build something interesting. I’ll show 3 example: one analog, one digital, and one mixed.

CircuitCim Framework

4 minute read

Framework

To code SPICE, the main challenges are: how do you keep the component information, and how do you tell which value goes where

MOSFETS: Multivariable Nonlinear

5 minute read

After building the framework for nonlinear components, I want to step into transistors. There are two choices:

  • BJT: CCCS
  • MOS: VCCS

More (Static) Linear Components

2 minute read

More Linear Components

Here is a set of more linear elements. Voltage sources need an additional row from MNA (instead of supernodes in the Tsividis textbook, because we do want to keep track of every subnode in the supernode)

typedef struct { 
    int n1, n2, ni;             // VSrc has an internal node
    float *V;
} VSrc;   
// dependent sources
typedef struct { 
    int n1, n2;
    int np, nn, ni;   
    float A;         // gain    
} Vcvs;
typedef struct { 
    int n1, n2;
    int np, nn;
    float A; 
} Vccs;

Register functions

void add_vsrc(int n1,int n2, int ni, float V) {
    // ni for an internal node for an extra row in the equation.
    Component *c = &comps[ncomps++];
    c->type      = STA_T;
    c->stamp     = vsrc_stamp;
    c->u.vsrc    = (VSrc){n1,n2, ni, V};
}
void add_vcvs(int n1, int n2, int np, int nn, int ni, float A) {
    Component *c = &comps[ncomps++];
    c->type      = STA_T;
    c->stamp     = vcvs_stamp;
    c->u.vcvs    = (Vcvs){n1,n2, np,nn, ni, A};
}
void add_vccs(int n1, int n2, int np, int nn, float A) {
    Component *c = &comps[ncomps++];
    c->type      = STA_T;
    c->stamp     = vccs_stamp;
    c->update    = NULL;
    c->u.vccs    = (Vccs){n1,n2, np,nn, A};
}

Update functions ```c /* add an ideal voltage source; stamps a “virtual” node (ni) to the circuit.*/ void vsrc_stamp(Component *c, float Gm[][MAT_SIZE], float I[]) { VSrc *s = &c->u.vsrc; float E = vsrc.V;

Time Variance

5 minute read

Now let’s add another dimension to our simulation: time

AP Notes.md

74 minute read

This file may not be fully adapted for web. Download the raw file here

1 Git Version Control

5 minute read

  • git diff shows unstaged changes
    • compares to the last commit if staging area empty (if haven’t git added)
    • git diff --cached shows staged changes

10 Domain Sockets

5 minute read

UNIX IPC Summary

Shared Memory

  1. Multiple threads in the same process
    • Process address space shared
    • Need synchro
  2. Multiple related processes
    • Anonymous mapping mmap() with MAP_SHARED | MAP_ANONYMOUS, and then fork()
  3. Multiple unrelated processes
    • mmap() with MAP_SHARED, backed up by a real file with open(), or virtual file with shm_open()

11 x86-64 Assembly

8 minute read

Data format and registers

16 64-bit general purpose registers (super fast memory locations)

12 Interrupts

4 minute read

Debugger breakpoint

How is it implemented? Tracer fork()s, and the child program becomes the tracee, but before that, makes a syscall ptrace(), so the parent process can control this.

13 ELF

less than 1 minute read

Executable and Linking Format (for Linux)

  1. readelf reads executable and finds all information
  2. Go through all the symbols, see if the calling return address falls between

15 UNIX File System

2 minute read

Single root directory, not necessarily a single device Need to designate a disk to be the root file system For external devices’ file system, need to mount it to some place at that file system

  • mount -l shows all mount points
    /dev/sda1 on / type ext4
    students251 on /mnt/disks/aspstudents251 type zfs
    
  • dev: a region for devices
  • sda1: hard disk device
  • type ext4: Metadata structure to use this device

16 Linux Container

7 minute read

VM and container

VM: Guest OS kernel run on top of a host OS (with the help of specialized software) controlling the actual hardware

  • Give the illusion of physical machine to the guest OS
  • Processes still touch the hardware, translation may be needed.
  • VMs do not know the existence of each other
  • Pro: Hard separation, very secure
  • Con: each VM runs an entire OS kernel: resource intensive Container: A group of processes that has its own view of the underlying hardware and OS
  • One OS
  • Not complete isolation
  • Need to make sure processes in different containers can’t communicate

3 Process Control

1 minute read

ps axf     # display process tree
ps axfj    # with more info
ps axfjww  # even if lines wrap around terminal

4 Signals

4 minute read

Signals and system calls

Sending signals

#include <signal.h>
int kill(pid_t pid, int signo);
int raise(int signo);    // same as kill(), but yourself
  • Both return: 0 if OK, -1 on error
  • if pid < 0, the signal is sent to the process group with pgid == |pid|

5 File IO

3 minute read

System calls

open()

int open(const char *path, int oflag, mode_t mode);
  • mode for file permission if new file created

6 Threads

14 minute read

Creating threads

An execution inside a process (two functions in a process running at the same time), sharing the same address space (same heap, same static var, but can’t share stack space) ^4bba4d

  • When thread starts running, the OS assigns a new slab of space in the middle for stack.
    • Limit of stack space for each process
      #include <pthread.h>
      int pthread_create(pthread_t *thread, 
                    const pthread_attr_t *attr,
                    void *(*start_routine)(void *), 
                    void *arg); 
      int pthread_join(pthread_t thread, void **retval);
      
  • thread: thread ID
  • attr: typically NULL, a fine-grain control of thread behavior
  • start_routine: input void *, return void *
  • arg: for start_routine(arg)
  • retval: stores the return value of start_routine() Returns 0 if OK, error number on failure

7 Synchronization

3 minute read

Semaphore

Integer value manipulated by two methods

  1. Increment (aka V, up, sem_post())
  2. Decrement: wait until value > 0, then decrease value (aka P, down, sem_wait())
    • Blocks until value is not 0.

8 Interprocess Communication

3 minute read

Pipes

Unnamed pipe

No file name, just an fd

#include <unistd.h>
int pipe(int fd[2]);

Kernel prepares a pipe structure, connecting fd[0] (read) with fd[1] (write) After fork(), parent and child will share the same pipe.

  • Pipe is one-way traffic (half duplex)
  • Need to close() unused ends of pipe

9 IO Blocking and Multiplexing

5 minute read

Nonblocking IO

Making slow (blocking forever) syscalls nonblocking

  • Call open() with `O_NONBLOCK
  • Call fcntl() (file control) to turn on o_NONBLOCK file status flag on already opened fd
    • Will be recorded in the file table entry
  • Returns -1 and sets errno to EAGAIN if were to block

courses

AP

Welcome to AP!

projects

publications

An Improved Machine Learning Model for Pure Component Property Estimation

2024

A new Gaussian Process-based modeling framework that predicts the physico-chemical properties of chemical species.

Recommended citation: Cao, X., Gong, M., Tula, A., Chen, X., Gani, R., & Venkatasubramanian, V. (2024). An improved machine learning model for pure component property estimation. Engineering, 39, 61–73. https://doi.org/10.1016/j.eng.2023.08.024
Download Paper

Loss Function Evaluation

2025

Accurate tracing of grain boundaries in microscopy images is vital in material science, yet current models need more data and a more accurate loss function. In this report, we present a twofold contribution to improving grain-tracing U-nets.

Download Paper

talks

teaching

Physics

Class Tutor, Bard College at Simon's Rock, 2023