import numpy as np
import bokeh.io
import bokeh.plotting
bokeh.io.output_notebook()
# Generate plotting values
t = np.linspace(0, 2 * np.pi, 200)
x = 16 * np.sin(t) ** 3
y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
# Make the plot
p = bokeh.plotting.figure(frame_width=300, frame_height=300)
p.line(x, y, line_width=3, color="red")
source = bokeh.models.ColumnDataSource(
dict(x=[0], y=[0], text=["Biocircuits"])
)
p.text(
x="x",
y="y",
text="text",
source=source,
text_align="center",
text_font_size="18pt",
)
# Display
bokeh.io.show(p)Appendix A — Configuring your computer to use Python for scientific computing
A.1 Why Python?
As will become readily apparent even at the beginning of our journey into biological circuit design, you will need to use your computer to analyze circuits and understand the principles governing their function. There are plenty of approaches we could take, and many languages we could use for computing as well. Indeed, in addition to Python, Matlab/Octave, Mathematica, R, Julia, Java, JavaScript, C++, and others are widely used. We have chosen to use Python. Though we view this as an unessential choice (we believe language wars are counterproductive and welcome anyone to port the code we use to any language of their choice), we nonetheless feel we should explain our choice.
Python is a flexible programming language that is widely used in many applications. This is in contrast to more domain-specific languages like R and Julia. It is easily extendable, which is in many ways responsible for its breadth of use. We find that there is a decent Python-based tool for many applications we can dream up, certainly in systems biology. However, the Python-based tool is seldom the very best for the particular task at hand, but it is almost always pretty good. Thus, knowing Python is like having a Swiss Army knife; you can wield it to effectively accomplish myriad tasks. Finally, we also find that it has a shallow learning curve with most students.
That said, if we had to choose another language, it would be Julia. Julia is a well-designed, modern language for scientific computing. Its tools for numerical differential equations, an important method we employ, are superb.
A.2 Why not use systems biology packages?
There are packages available to streamline systems biology calculations, such as PySB or Matlab’s SymBiology. While these packages are useful, we find that many applications in systems biology, and in genetic circuits in particular, need, or at least benefit from, bespoke computational analyses. We therefore will build all of our code from scratch, using only packages like NumPy, SciPy, and Bokeh, which contain core numerical and plotting data structures and routines. Of course, code we use in one chapter may be reused in another, but our approach is that we build all of the code we need as we go along. This will provide a greater level of mastery and less reliance on black boxes (though there will inevitably be some).
A.3 The biocircuits package
For some of those black boxes, we will use the biocircuits package, which is written to be used with this book. The functions contained therein are presented before being abstracted away into the package. Thus, anything that is in the package is introduced in the main text and you should have a full understanding of how it works.
The documentation for this package appears at the end of this book.
A.4 What to do if you are new to Python
As you proceed through the chapters, we assume that you have a basic introduction to computer programming and the Python programming language. We assume further that you have a working knowledge of NumPy. If this is new to you, you can work through Appendix B to get up to speed. In fact, for some of the programming techniques we learn, such as making interactive plots, we will refer to Appendix B.
A.5 Jupyter notebooks
This book is constructed from Jupyter notebooks. To quote Jupyter’s documentation,
Jupyter Notebook and its flexible interface extends the notebook beyond code to visualization, multimedia, collaboration, and more. In addition to running your code, it stores code and output, together with markdown notes, in an editable document called a notebook.
This allows for executable documents that have code, but also richly formatted text and graphics, enabling the reader to interact with the material as they read it.
While you read this book, you can read the HTML-rendered version of the notebook. While many of the graphics are interactive, this version is not executable. To execute (and even edit) code in the notebooks, you will need to run them. There are many options available to run Jupyter notebooks. Here are a few we have found useful.
- JupyterLab: This is a browser-based interface to Jupyter notebooks and more (including a terminal application, text editor, file manager, etc.). As of March 2026, Chrome, Firefox, and Safari are supported. Microsoft Edge is not. Therefore, if you are a Windows user, you need to be sure you have either Chrome of Firefox installed. Because we encourage users to run code on their own machine (and because nearly every computer has a browser application), we expect most of our readers to use JupyterLab. We give instructions below on how to do the necessary installations and launch JupyterLab.
- VSCode: This is an excellent source code editor that supports Jupyter notebooks. Be sure to read the documentation on how to use Jupyter notebooks in VSCode.
- Google Colab: Google offers this service to run notebooks in the cloud on their machines. As of March 2026, users can run on two core machines for free. There are a few caveats, though. First, not all packages and updates are available in Colab. Furthermore, not all interactivity that will work natively in Jupyter notebooks works with Colab. Finally, if a notebook sits idle for too long, you will be disconnected from Colab. All of the notebooks in the HTML rendering of this book have an “Open in Colab” button at the upper right that allows you to launch the notebook in Colab. This is a quick-and-easy way to execute the book’s contents.
A.6 Installing a Python distribution
Prior to embarking on your journey into biological circuits, you need to have a functioning Python distribution installed on your computer. There are several ways people set up Python for scientific computing.
- By downloading and installing package by package using pip.
- By downloading and installing a Python distribution that contains binaries of many of the scientific packages needed. Anaconda is the dominant distribution for scientific and data science computing.
- Using newer package managers like UV, which has more bells and whistles, like the ability to run scripts and deploy packages you like.
- With project-based package managers. That is, for each project, you use the package manager to create and manage the packages needed for that project.
We will use Pixi, which falls into this last category. Our “project” here is working through this book on biological circuit design.
Step 1: Install Pixi. To install Pixi, you need access to the command line. For macOS users, hit Command-space, type in “terminal” and open the Terminal app. In Windows, open PowerShell by opening the Start Menu, typing “PowerShell” in the search bar, and selecting “Windows PowerShell.” I assume you know how to get access to the command line if you are using Linux.
On the command line, do the following.
macOS or Linux
curl -fsSL https://pixi.sh/install.sh | sh
Windows
powershell -ExecutionPolicy ByPass -c "irm -useb https://pixi.sh/install.ps1 | iex"
Step 2: Create a directory for your work. You might want to name the directory biocircuits/, which is what I have named it. You can do this either with the command line of your graphical file management program (e.g., Finder for macOS).
Step 3 Navigate to the directory you created on the command line. For example, if the directory is biocircuits/ in your home directory and you are in your home directory, you can do
cd biocircuits
on the command line.
Step 4 Download the requisite Pixi file: pixi.toml, which instructs Pixi on which packages need to be installed. The packages included there are a standard set of packages for scientific computing, plus a few domain-specific ones for analysis of biological circuits. The pixi.toml file needs to be stored in the directory you created in step 3. You may download it by right-clicking this link (pixi.toml) or by doing the following on the command line.
macOS or Linux
curl -fsSL https://raw.githubusercontent.com/biocircuits/biocircuits.github.io/refs/heads/main/pixi.toml
Windows
irm -useb https://raw.githubusercontent.com/biocircuits/biocircuits.github.io/refs/heads/main/pixi.toml -OutFile pixi.toml
Step 5 Install the environment! Do the following on the command line.
pixi install
Step 6 To be able to use all of the packages, you need to invoke a Pixi shell. To do so, execute the following on the command line.
pixi shell
You are now good to go! After you are done working, to exit the Pixi shell, hit Control-D.
You will need to cd into the directory you created in step 2 and execute pixi shell every time you open a new terminal (or PowerShell) window.
A.7 Launching JupyterLab
Once you have invoked a Pixi shell, you can launch JupyterLab via your operating system’s terminal program (Terminal on macOS and PowerShell on Windows). To do so, enter the following on the command line (after having run pixi shell).
jupyter lab
You will have an instance of JupyterLab running in your default browser. If you want to specify the browser, you can, for example, type
jupyter lab --browser=firefox
on the command line.
Within the JupyterLab window, you will have the option to launch a notebook, a console, a terminal, or a text editor. As you work through this book, you will use notebooks almost exclusively.
Alternatively, if you are using VSCode, you can use its menu system to open .ipynb files. Make sure you select the Python kernel corresponding to your environment. You can read the documentation here. Hint: You may need to restart VSCode after doing the above installations so it is aware of your pixi environment.
A.8 Checking your distribution
Let’s now run a quick test to make sure things are working properly. We will make a quick plot that requires some of the scientific libraries we will use in this book.
Launch a Jupyter notebook in JupyterLab. In the first cell (the box next to the [ ]: prompt), paste the code below. To run the code, press Shift+Enter while the cursor is active inside the cell. You should see a plot that looks like the one below. If you do, you have a functioning Python environment for scientific computing!
Computing environment
At the end of each chapter in this book, all of which are constructed from a Jupyter notebook, we will show what versions of the employed packages were used. This will help you troubleshoot if your outputs look dissimilar from what is on the book website.
We use the handy watermark package to do this.
%load_ext watermark
%watermark -v -p numpy,bokeh,jupyterlabPython implementation: CPython
Python version : 3.13.12
IPython version : 9.10.0
numpy : 2.2.6
bokeh : 3.8.2
jupyterlab: 4.5.4