The Simulation Object

Overview

Questions

  • How can I configure and control a simulation?

  • How do I choose which processor to use?

Objectives

  • Explain the parts of the Simulation object and how they relate.

  • Explain how the device object influences how the simulation executes.

  • Demonstrate the creation of these objects.

Core objects

HOOMD-blue is an object-oriented Python package. First, import the package:

[1]:
import hoomd

The Simulation object combines all the elements of a simulation together and provides an interface to run the simulation. It consists of the simulation state and operations which act on that state. The simulation state includes the current box, bonds, particle positions, velocities, orientations, and other particle properties. Operations examine or modify the state. A simulation has one state, and any number of operations.

Selecting a device

You must specify a device when constructing a Simulation. The device tells the simulation where to store the state and what processor to use when executing operations. HOOMD-blue can execute on the CPU:

[2]:
cpu = hoomd.device.CPU()

Or the GPU:

[3]:
gpu = hoomd.device.GPU()

GPUs are highly parallel processors best suited for larger workloads. In typical systems with more than 4,000 particles a single GPU performs an order of magnitude faster than an entire CPU (all cores). Try your simulation on both to see what hardware can run the same number of time steps in less time.

Creating a Simulation

Now, you can instantiate a Simulation with the chosen device.

[4]:
sim = hoomd.Simulation(device=gpu)

A newly constructed Simulation has no state:

[5]:
print(sim.state)
None

And no integrator, updaters, or writers, which are types of operations:

[6]:
print(sim.operations.integrator)
None
[7]:
print(sim.operations.updaters[:])
[]
[8]:
print(sim.operations.writers[:])
[]

The remaining sections in this tutorial will show you how to populate a Simulation with operations, initialize the state, and run the simulation.