[learning_to_simulate] Exclude kinematic particles from evaluation MSE metrics
Bug description
The learning_to_simulate training and evaluation pipeline appears to handle kinematic particles inconsistently when calculating evaluation metrics.
In get_one_step_estimator_fn(), kinematic particles are explicitly excluded from the training loss through non_kinematic_mask:
non_kinematic_mask = tf.logical_not(
get_kinematic_mask(features['particle_type'])
)
loss = (pred_acceleration - target_acceleration) ** 2
loss = tf.where(non_kinematic_mask, loss, tf.zeros_like(loss))
loss = tf.reduce_sum(loss) / tf.reduce_sum(num_non_kinematic)
However, the evaluation metrics are calculated without applying this mask:
eval_metrics_ops = {
'loss_mse': tf.metrics.mean_squared_error(
pred_acceleration, target_acceleration),
'one_step_position_mse': tf.metrics.mean_squared_error(
predicted_next_position, target_next_position)
}
This means evaluation includes predictions for kinematic particles even though these particles are excluded from the training objective.
There is a related inconsistency in rollout evaluation.
In rollout(), predicted positions for kinematic particles are replaced with their ground-truth positions:
kinematic_mask = get_kinematic_mask(features['particle_type'])
next_position_ground_truth = ground_truth_positions[:, step]
next_position = tf.where(
kinematic_mask,
next_position_ground_truth,
next_position
)
The resulting rollout predictions are subsequently passed to tf.metrics.mean_squared_error() without excluding kinematic particles.
Consequently, kinematic particles contribute zero prediction error by construction during rollout evaluation, potentially making the reported rollout error artificially low.
Why this is a problem
The evaluation metrics should consistently measure the particles whose dynamics are actually being learned.
The current behavior creates two problems:
- One-step evaluation can include errors from kinematic particles that are excluded from training.
- Rollout evaluation includes kinematic particles whose predictions have already been replaced by ground truth.
As a result, evaluation scores can be misleading and may vary with the proportion of kinematic particles in a trajectory, even when the model's performance on simulated particles remains unchanged.
Steps to reproduce
- Load a dataset containing both normal and kinematic particles.
- Run one-step evaluation using
get_one_step_estimator_fn(). - Observe that the training loss masks out kinematic particles, but
loss_mseandone_step_position_msedo not. - Run rollout evaluation.
- Observe that kinematic predictions are replaced with ground-truth positions before
rollout_error_mseis calculated. - Compare the reported metrics with an evaluation that excludes kinematic particles.
A useful synthetic test would contain one normal particle and one kinematic particle. Changing only the kinematic particle's model prediction should not change the evaluation score if the intended evaluation objective is to measure learned particle dynamics.
Expected behavior
Evaluation metrics should consistently exclude kinematic particles, following the same masking principle used in the training loss.
The correction should cover:
loss_mseone_step_position_mserollout_error_mse
The implementation should also preserve correct metric aggregation across batches and evaluation steps, including distributed evaluation where applicable.
Suggested tests
- Verify that kinematic particles do not contribute to one-step evaluation metrics.
- Verify that kinematic particles do not contribute to rollout evaluation metrics.
- Confirm that changing kinematic particle predictions does not change the reported metrics.
- Confirm that metrics remain correct with different proportions of normal and kinematic particles.
- Ensure existing evaluation behavior remains unchanged for datasets without kinematic particles.
Expected outcome
Training, one-step evaluation and rollout evaluation should use a consistent definition of the particles whose dynamics are being evaluated.
This would prevent ground-truth-overridden particles from artificially influencing reported model performance.