Skip to content

CFT-HY/phi4-pybind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simulations with Pybind11 & C++

Prerequisites

  • C++ Compiler: GCC or Clang (C++14 or higher required).
  • OpenMP:

Environment Setup

# 1. Create and activate a virtual environment
python -m venv env
source env/bin/activate 
# 2. Install dependencies for all workshop stages
pip install -r requirements.txt

Running example notebooks

Launch Jupyter from the root directory of this repository and install the env as a usable kernel:

source env/bin/activate
python -m ipykernel install --user --name=phi-4-env --display-name="Phi4"
jupyter notebook

Navigate through the folders and open the notebooks in order:

  1. 01-Python/01_notebook.ipynb
  2. 02-Python-Pybind/02_notebook.ipynb
  3. 03-Python-Pybind-OMP/03_notebook.ipynb

C bindings can be compiled in each respective folder but also in the notebook directly

!make

Comparing performance

Compare the performance of each respective implementation. (Already found in notebook)

import time
import matplotlib.pyplot as plt
import pandas as pd
# 1. Initialize
L_scaling = [2**i for i in range(6,14)]
sweep_time = []
for L in L_scaling:
    sim = Lattice(L=L, kappa=0.4, lambda_=0.1)
    N_updates = 100
    # 2. Run and measure
    start_time = time.perf_counter()
    
    for i in range(N_updates):
        sim.update()
        
    end_time = time.perf_counter()
    sweep_time.append((end_time - start_time)/N_updates)


df_results = pd.DataFrame({
    "L": L_scaling,
    "SweepTime_Seconds": sweep_time
})
df_results["Model"] = "OpenMP" 
print(df_results.to_markdown(index=False))
df_results.to_csv("performance_openmp.csv", index=False)

About

Pybind example with phi^4 theory

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors