This project implements a high-performance Markov Chain Monte Carlo (MCMC) simulation of the 2D Ising Model to investigate statistical mechanics and critical phenomena. It features a physics-grade simulation engine, comprehensive thermodynamic analysis, and interactive visualization tools.
Key Physics Explored:
- Phase Transitions: Second-order ferromagnetic-paramagnetic transition.
-
Critical Phenomena: Divergence of correlation length and susceptibility near
$T_c$ . -
Finite-Size Scaling: Extraction of critical exponents (
$\nu, \gamma, \beta$ ). - Hysteresis: Dynamic magnetic memory and coercivity.
- Universality: Validation of the 2D Ising universality class.
We observe the classic symmetry breaking at the Onsager critical temperature
Using Finite-Size Scaling (FSS), we collapsed data from lattice sizes
| Metric | Measured | Theory |
|---|---|---|
Below
We measured the spin-spin correlation function
Building on the statistical mechanics simulation of the 2D Ising Model, Phase 2 implements a Hopfield Network to investigate the emergence of associative memory. By extending the Ising formalism to include non-local, programmable couplings (
Theoretical Foundation: The Hopfield network is mathematically isomorphic to an Ising model with long-range interactions. The "Energy" of the spin system is equivalent to a Lyapunov function for the network dynamics, ensuring that the system always evolves towards energy minima. These minima represent stored "memories."
-
Hebbian Learning Rule: Weights are constructed via the outer product of target patterns:
$W_{ij} = \frac{1}{N} \sum_{\mu} \xi_i^\mu \xi_j^\mu$ . -
Asynchronous Dynamics: Neurons update stochastically or sequentially, minimizing the global energy
$E = -\frac{1}{2} \sum_{i,j} W_{ij} s_i s_j$ . - Pattern Corruption & Restoration: Capability to recover perfect patterns from inputs degraded by noise (e.g., 30-50% flipped bits).
-
Capacity Analysis: Empirical verification of the storage capacity limit (
$C \approx 0.14N$ ).
We quantified the network's performance using orthogonal bit patterns on a
| Experiment | Condition | Measured Success | Theoretical Expectation |
|---|---|---|---|
| Robustness | Noise |
Perfect Retrieval | |
| Robustness | Noise = 50% | Unstable (Random) | |
| Capacity | Low Load ( |
Global Minima Stable | |
| Capacity | High Load ( |
Spin Glass Phase (Overload) |
We demonstrated the network's error-correction capability by initializing it with a corrupted version of a stored pattern (e.g., the letter 'A' with varying noise levels). The network dynamics successfully evolved the state down the energy gradient to the original clean pattern.
We analyzed the network's performance as the number of stored patterns (
-
Success Regime: For
$P < 0.14N$ , the network reliably retrieves memories. -
Failure Regime: As
$P$ exceeds the capacity limit, "crosstalk" between patterns creates spurious local minima (spin glass phase), causing the network to converge to "hallucinated" mixed states rather than pure memories.
We utilized a custom utility to generate orthogonal bit patterns (e.g., 'Y', 'H', 'E', 'I', 'A') to rigorously test the network's ability to discriminate between distinct memories.
To reproduce the Hopfield network experiments:
# 1. Run Single Pattern Validity Test
python experiments/experiment_1_single_pattern.py
# 2. Run Capacity Analysis
python experiments/experiment_2_capacity.py
# 3. View Pattern Utilities
python experiments/test_utils_visual.pyExplore the physics in real-time with the included Streamlit dashboard:
pip install -r spin-equilibrium/requirements.txt
streamlit run spin-equilibrium/viz/dashboard.pyFeatures:
-
Live Controls: Adjust Temperature (
$T$ ), Field ($B$ ), and Coupling ($J$ ). - Real-time Plotting: Watch Magnetization and Energy evolve.
- Phase Diagram Tracker: See your current state vs. the Onsager solution.
Reproduce all experiments (Thermodynamics, Hysteresis, Scaling):
python experiments/run_simulation.py
python experiments/hysteresis_loop.py
python experiments/fss_run.pyCreate publication-quality figures from collected data:
python experiments/generate_plots.py
python experiments/fss_analyze.pyA clean, installable version of the core logic is provided in ising_simulation/.
cd ising_simulation
pip install -e .spin-equilibrium/: Original source code and modules.experiments/: Scripts for running physics experiments.results/: Data, Figures, and Animations.ising_simulation/: Refactored professional Python package.
MIT License.







