4. Computer Hardware Germane to Running a Program#
Your computing machine has many components to it and we are going to look at some of the key components used when running software on your computer. Our goal is to get a bearing on what happens when you load and run a Jupyter notebook. PBS has a great Youtube channel for their Crash Course in Computer Science that is well worth the time to watch.
Central Processing Unit (CPU)#
Function: The CPU is the “brain” of the computer, performing all processing tasks. It executes instructions from programs by performing arithmetic, logic, control, and some input/output operations.
Key Parts:
Cores: Perform multiple tasks simultaneously (multi-core CPUs handle parallel processing).
Clock Speed: Determines how fast the CPU processes instructions.
Memory#
Random Access Memory (RAM)#
Function: RAM is temporary, high-speed storage that holds data and instructions currently in use by the CPU. It enables fast access and multitasking but loses data when power is off.
Heap Memory - RAM memory for stored objects (variables)
Memory Block - unit of memory allocated to an object on the HEAP
reference or pointer - address of the memory block
Stack Memory - RAM memory for function calls
Cache Memory#
Small, ultra-fast stored near or in CPU.
Stores frequently accessed data and instructions to speed up processing.
Levels
L1 Cache Closet to CPU, smallest and fastest
L2 Cache Larger but slower
L3 Cache Shared among CPU cores, largest and slowest.
Virtual Memory#
Located on hard drive or SSD
used as “backup” when RAM is physically full
ROM (Read-Only Memory)#
Non-volatile memory (persists after computer shuts down)
Used to boot up computer
Register Memory#
Located inside CPU, used to store data being processed at the moment
Storage Drive#
Types:
Hard Disk Drive (HDD): Uses spinning disks to store data magnetically; slower but cheaper.
Solid State Drive (SSD): Uses flash memory; faster, more durable, and energy-efficient.
Function: Stores the operating system, applications, and user files permanently.
Graphics Processing Unit (GPU)#
Function: Specialized for rendering images, video, and animations. Also used for parallel processing in tasks like machine learning and simulations.
Integrated vs. Dedicated:
Integrated GPU: Built into the CPU, suitable for general tasks.
Dedicated GPU: Separate hardware for high-performance tasks like gaming or 3D modeling.
2. Role of Python Interpreter#
The Python Interpreter is responsible for the following:
I. Read and convert human readable Python Source Code (*.py file) to bytecode.
Compiles the entire file
Creates sequence of bytecode instructions (control-flow structures, function calls..)
II. Execute code (line by line)
Fetch Data
Retrieve data stored in heap
Look up metadata and ensure operations are valid
Perform Operations
Arithmetic operations
String manipulations
Type conversions
Handling Control-Flow Operations
Conditionals (if statement), Loops (for, while), exceptions (try-except)
Evaluate True/False statements (x>0)
Allows program to make decisions and repeat tasks
Calling and Executing Functions (from heap)
Creates stack frame to hold functions local variables and execute content
Execute functions bytecode step-by-step
Clean stack frame and return result
Return and Store Results
Create new Python objects
Store new objects on heap
3. Steps When Running Jupyter Lab:#
Launch Jupyter Lab:
A Conda environment with Jupyter is activated.
The
jupyter-lab
command starts a local server, which the OS runs as a process.The server uses OS (Ubuntu) network interfaces to open a port (e.g.,
localhost:8888
) for browser-based access. Note, you can run more than one localhost address at the same time.
Open a Notebook:
The Jupyter Lab interface sends a request to the server to open a
.ipynb
file.The server spawns a kernel (IPython process) for the environment in which the notebook is running.
This kernel is connected to the Conda Environment to ensure the needed libraries are available.
Code Execution:
When you run a code cell, the code is sent to the kernel.
The kernel interacts with the Python interpreter within the Conda environment, which executes the code.
Outputs are sent back to the notebook via the server.
File Access and Visualization:
The notebook can read/write files on the system via Python, using OS file system APIs.
Visualizations (e.g., plots) are rendered in the notebook interface using libraries like matplotlib.
Acknowledgements#
This content was developed with assistance from Perplexity AI and Chat GPT. Multiple queries were made during the Fall 2024 and the Spring 2025.