Skip to content

Fix: Prevent kspaceFirstOrder3D from modifying input source and sensor #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

waltsims
Copy link
Owner

The kspaceFirstOrder3D simulation function was unintentionally modifying the input source and sensor objects. This occurred because the internal kWaveSimulation object and its helper functions were operating directly on these mutable input objects.

This commit addresses the issue by:

  1. Modifying kWaveSimulation.__init__ to create deep copies of the input source and sensor objects. All internal operations within kWaveSimulation and its helper functions (like save_to_disk_func and retract_transducer_grid_size) now use these copies. The original objects you passed remain unchanged.

  2. Adding a regression test (tests/test_kspaceFirstOrder3D_state.py). This test verifies that critical attributes of the source and sensor objects (e.g., source.p0, sensor.mask) are not altered after calls to kspaceFirstOrder3D, and that the function can be called multiple times with the same input objects without error or state corruption.

This ensures that the source and sensor states remain consistent, allowing them to be reused for multiple simulations or checkpointing without unexpected side effects, resolving bug #600.

…sensor

The kspaceFirstOrder3D simulation function was unintentionally modifying
the input `source` and `sensor` objects. This occurred because the
internal `kWaveSimulation` object and its helper functions were
operating directly on these mutable input objects.

This commit addresses the issue by:
1. Modifying `kWaveSimulation.__init__` to create deep copies of the
   input `source` and `sensor` objects. All internal operations within
   `kWaveSimulation` and its helper functions (like `save_to_disk_func`
   and `retract_transducer_grid_size`) now use these copies.
   The original objects you passed remain unchanged.

2. Adding a regression test (`tests/test_kspaceFirstOrder3D_state.py`).
   This test verifies that critical attributes of the `source` and
   `sensor` objects (e.g., `source.p0`, `sensor.mask`) are not altered
   after calls to `kspaceFirstOrder3D`, and that the function can be
   called multiple times with the same input objects without error or
   state corruption.

This ensures that the `source` and `sensor` states remain consistent,
allowing them to be reused for multiple simulations or checkpointing
without unexpected side effects, resolving bug #600.
@waltsims waltsims closed this May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant