Counting the number of Alive particles Im working on a predator-prey model, and to get some useful information I want to extract the number of Alive particles at any given frame. However, I got the blender file sent from another person working on this. And the number of Alive boids is stuck on whatever value he had when sending the file. So for a 1000 boids 933 is Alive and whatever I do this does not change.

import bpy


obj  = bpy.context.object     # Active object
p_s = obj.particle_systems.active # Active particle system
print(p_s.settings.count)

AliveP = len([ 
    p for p in p_s.particles if p.alive_state == 'ALIVE' 
])

print(AliveP)
```
Use the dependency graph.
import bpy

# get the object
obj = bpy.context.object

# get current dependency graph
dg = bpy.context.evaluated_depsgraph_get()

# get the object as currently evaluated
e_obj = obj.evaluated_get(dg)

# get the particle system
ps = e_obj.particle_systems.active

# and count
print(len([p for p in ps.particles if p.alive_state == 'ALIVE']))

As said in the documentation:

This example demonstrates access to the evaluated ID (such as object,
material, etc.) state from an original ID. This is needed every time
one needs to access state with animation, constraints, and modifiers
taken into account.