levisim.data.simulation¶
Stochastic Runge-Kutta simulation (Simulation) of the motion of a bead in a free-space tweezer trap
- class levisim.data.simulation.Simulation(**kwargs)[source]¶
Bases:
objectTweezer-bead dynamics simulated using a Runge-Kutta (RK) stochastic numerical solver
Integrates the Langevin equations of motion of a bead in a free-space Trap,
dX = F(t, X) dt + G dW, X = [x, y, z, px, py, pz]
(see dynamics_vector and noise_matrix_RK4), and stores the recorded position traces self.x, self.y, self.z (Trace instances, also in self.traces).
Keyword arguments (defaults in brackets):
trap [Trap()]: the Trap whose physics is simulated num_samples [1e6]: number of time steps Δt [0.1 μs]: time step [s] X0 [zeros]: initial [x, y, z, px, py, pz] (photon recoil is switched on with Trap(photon_recoil=True), see Trap.F_scattering) RK_method ['vector_4']: 'vector_4' (Kasdin stochastic RK4) or 'vector_2' (improved Euler) seed [None]: None uses numpy's legacy global RandomState (reproducible with np.random.seed); an int (or SeedSequence / Generator) uses np.random.default_rng(seed) gravity [False]: add the bead's weight m·g along gravity_direction [(-1, 0, 0), i.e. -x]; it shifts the equilibrium by g/Ωj² (≈ 10 pm in x for the defaults) detection_floor [0]: one-sided white displacement-noise PSD [m²/Hz] added to the recorded traces only (a number, or a dict per axis) zero_mean [True]: subtract each trace's mean store_momenta [False]: also store px, py, pz traces [kg·m/s] (self.px etc., traces 'px', ...) store_radial [False]: also store the radial trace r = √(x² + y²) [m] (self.r, traces 'r') save, save_dir, save_description, save_fmt: optional pickling of the instance- property info¶
Prints a summary of the simulation’s settings and of its position traces
- property save_name¶
Returns standardised naming format for the pickle binaries
- dynamics_vector(t, X)[source]¶
Deterministic part of the equations of motion, dX = F(t, X) dt + G dW
F = (px/m, py/m, pz/m, Ftw,x - Γx px + F_kick,x, Ftw,y - Γy py + F_kick,y, Ftw,z - Γz pz)
i.e. Hamilton’s equations for
H = |p|²/2m + Utw(r), plus the (gas + feedback) damping and any Kick impulses active at time t. [m/s, m/s, m/s, N, N, N]
- noise_matrix_RK4(t, X)[source]¶
Noise matrix G of the equations of motion dX = F dt + G dW (used by every RK_method)
dynamics noise matrix (6 x 4) | dx | | px/m | | 0 0 0 0 | | dy | | py/m | | 0 0 0 0 | | dz | | pz/m | | 0 0 0 0 || dWx | | | = | | dt + | || dWy | | dpx | | -dU/dx - Γpx | | 1 0 0 cos(ψ) || dWz | | dpy | | -dU/dy - Γpy | | 0 1 0 sin(ψ) || dWdir | | dpz | | -dU/dz - Γpz | | 0 0 1 0 |
dWx,y,z and dWdir are four independent Wiener processes that carry their physical variances, i.e. the (two-sided) force spectral densities Sth and Sdir = β²Sth, whose square roots are the force noise floors fth and fdir. The same dWdir enters x and y, weighted by cos(ψ) and sin(ψ), which is what correlates the x, y motion (a non-zero Sxy).
G does not depend on (t, X), i.e. the noise is additive, so the Itô and Stratonovich interpretations of the equations of motion coincide. [·]
- standard_normals(shape)[source]¶
Standard normal random numbers N(0, 1) of the given shape, drawn from the simulation’s random number generator
seed=None (default): numpy’s legacy global RandomState (np.random.normal), so runs seeded with np.random.seed(…) reproduce the numbers of earlier levisim versions
otherwise: a numpy Generator, np.random.default_rng(seed)
Drawing an array from the legacy RandomState gives the same numbers, in the same (C) order, as drawing them one at a time, so pre-generating per chunk does not change the stream. [·]
- simulate_dynamics()[source]¶
Integrates the stochastic equations of motion dX = F(t, X) dt + G dW for X = [x, y, z, px, py, pz] and stores the position traces (plus the detection floor, if any) as Trace instances
RK_method: - ‘vector_4’ (default): Kasdin’s 4-stage stochastic Runge-Kutta method (see below) - ‘vector_2’: improved Euler (Heun) scheme for additive noise, strong order 1
The random numbers for each chunk of time steps are pre-generated (see standard_normals).
- detection_floor_for(axis)[source]¶
One-sided displacement PSD of the white detection (imprecision) noise for a given axis detection_floor may be a single number (all axes) or a dict {‘x’: …, ‘y’: …, ‘z’: …} [m²/Hz]
- add_detection_floor(values, axis)[source]¶
Adds white measurement noise to a recorded position trace (never to the integrated state)
Convention: detection_floor G_floor is the one-sided PSD [m²/Hz] of the noise, i.e. the flat level it produces far from resonance in a (default, one-sided) SpectralDensityEstimate. A white sequence of variance σ² sampled every Δt has one-sided PSD G = 2σ²Δt, hence σ = √(G_floor / (2Δt)). [m]
- property F_gravity¶
Weight of the bead along gravity_direction [N]
- property time_length¶
Time length of the simulation (seconds)
- property min_Δf¶
Minimum frequency resolution the time trace is capable of producing (Hertz)
- property sample_rate¶
Sample rate of the simulation - how many samples are taken per second? (samples/second)
- property Nyquist_frequency¶
The Nyquist frequency, a.k.a. the bandwidth of the simulation This will be the largest frequency in the spectral density estimate NOTE: https://en.wikipedia.org/wiki/Nyquist_frequency
- property time_array¶
Array of all the time steps in the simulation
- temperature_via_variance(axis, Ωj=None)[source]¶
Temperature estimated via the variance, using equipartition theorem
½mΩj²〈j²〉 = ½kb*Tj 〈j²〉= Var(j) Therefore expecting T = (mΩ² / kb) * Var(j) j = x, y, z
Ωj may be passed to account for how the simulated frequencies are shifted from the first order (harmonic) approximations; by default the Trap’s harmonic Ωj is used. NOTE: includes the detection floor’s variance if one was added to the trace. [K]