Kuramoto Model

Full Simulation

This part is optional and is meant to be a fun extension if you want to build a full simulation with sliders and live plots. It combines the previous two pages into a single interactive experience.

If you want to skip this part, you can go directly to the next page, which contains an assignment based on the same ideas.

Assignment

Template

You can start from the template in amlab/odes_coupled/kuramoto_full_template.py and fill in the missing parts. The template includes the structure for sliders, animation, and order parameter computation, so you can focus on implementing the Kuramoto model dynamics and visualizations.

Alternatively, you can build the full simulation from scratch by following the steps outlined in the previous pages and combining them together.

Order Parameter

Complete the function that computes the order parameter:

def kuramoto_order_parameter(theta: np.ndarray) -> tuple:
    # TODO: compute r * exp(i * phi)
    order_param =  # replace this line
    r = np.abs(order_param)
    phi = np.angle(order_param)
    rcosphi = np.real(order_param)
    rsinphi = np.imag(order_param)
    return r, phi, rcosphi, rsinphi
def kuramoto_order_parameter(theta: np.ndarray) -> tuple:
    order_param = np.mean(np.exp(1j * theta), axis=0)
    r = np.abs(order_param)
    phi = np.angle(order_param)
    rcosphi = np.real(order_param)
    rsinphi = np.imag(order_param)
    return r, phi, rcosphi, rsinphi

Sliders

Use sliders to update the coupling strength, number of oscillators, and the distribution scale. The template shows how to restart the animation when values change.

def update_sliders(_):
    nonlocal coupling_strength, num_oscillators, sigma, theta, omega
    coupling_strength = slider_coupling.val
    num_oscillators = int(slider_num_oscillators.val)
    sigma = slider_sigma.val
    theta, omega = initialize_oscillators(num_oscillators, sigma=sigma)

When you finish, run the full simulation and explore how synchronization changes as you vary \(K\).