This project has interactive simulations of both the quantum and classical Ehrenfest models (a.k.a. Ehrenfest-Urn model), showing how particles move between two “wells” or containers.
The Ehrenfest model is a classic experiment that allows us to observe how reversible behavior at the microscopic level can lead to irreversible behavior on a macroscopic scale.
This repository contains two complementary simulations:
The Quantum Ehrenfest Model explores how a quantum particle behaves when placed in a double-well potential. The simulation solves Schrödinger's equation to show how a wave packet evolves over time, demonstrating quantum tunneling, wave interference, and the probabilistic nature of quantum mechanics. One can observe how the probability of finding a particle in each well changes as the wave function evolves.
The Classical Ehrenfest Model (also known as the Ehrenfest-"flea" or the -"urn" model) simulates particles moving between two communicating containers. At each time step, a random particle is selected and moved to the other container. This simple process reveals deep insights about equilibrium, entropy, and the apparent irreversibility of macroscopic systems, even when the underlying dynamics are reversible.
Before running the simulations, it is necessary to set up a Python environment with the required dependencies. The project uses standard scientific Python libraries.
It's recommended to create a virtual environment to keep dependencies isolated. One can do this using Python's built-in venv module:
python3 -m venv ehrenfest_envThis creates a new directory called ehrenfest_env containing the virtual environment.
On macOS and Linux:
source ehrenfest_env/bin/activateOn Windows:
ehrenfest_env\Scripts\activateWhen the environment is active, the terminal prompt will show (ehrenfest_env) at the beginning.
Once the virtual environment is activated, install the required packages using pip:
pip install -r requirements.txtThis will install all necessary dependencies. Notice that is necessary to install Jupyter for notebook support, and ipywidgets for interactive controls. In the case of using a UI like VSCode or pycharm ensure that the ipykernel and jupyter extension is installed as well.
The project includes interactive Jupyter notebooks that allow one to explore the models with adjustable parameters. There are two main notebooks available:
ehrenfest_model_interactive.ipynbThe fully interactive version with widgets for real-time parameter adjustmentehrenfest_model.ipynbA standard notebook version with fixed parameters
To launch Jupyter Notebook, ensure the virtual environment is activated and run:
jupyter notebookThis will open Jupyter in the default web browser. From there, one can navigate to the project directory and open either notebook file. The interactive notebook (ehrenfest_model_interactive.ipynb) is particularly recommended, as it provides sliders and controls to adjust parameters in real-time and see how they affect the simulations.
Or through vscode or pycharm with jupyter support:
select the kernel corresponding to the created virtual environment and run the notebook files directly.
Once the notebook is open, one can run all cells sequentially (using "Run All" from the Cell menu) or step through them one at a time. The interactive widgets will appear below the parameter controls, allowing one to experiment with different values and observe the results immediately.
The simulations offer numerous parameters to experiment with:
For the Quantum Model:
- Initial position and momentum of the wave packet
- Width of the Gaussian wave packet
- Height of the potential barrier between wells
- Separation between the two wells
- Physical constants (though these are typically set to 1 for convenience)
For the Classical Model:
- Total number of particles
- Initial distribution between the two urns
- Number of time steps to simulate
- Multiple independent runs for comparison
By adjusting these parameters, one can observe how they influence the behavior of the systems, gaining intuition about quantum mechanics and statistical physics in the process.
The project requires Python 3.7 or higher and the following packages:
- NumPy (>=1.20.0)
- Matplotlib (>=3.3.0)
- SciPy (>=1.7.0)
- Jupyter (>=1.0.0)
- ipykernel (>=6.0.0)
- ipywidgets (>=7.6.0)
All dependencies are listed in requirements.txt and can be installed with a single pip command as described above.