-
Notifications
You must be signed in to change notification settings - Fork 57
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
Multiprocessing #486
Draft
nkrah
wants to merge
169
commits into
master
Choose a base branch
from
multiproc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Multiprocessing #486
Changes from 7 commits
Commits
Show all changes
169 commits
Select commit
Hold shift + click to select a range
fe4c659
Correct typo in comment
nkrah b66c665
Implement DynamicGateObject.reassign_subset_of_dynamic_params()
nkrah 0456d04
Add attribute process_index to SimulationEngine (not used yet)
nkrah 30526c8
First steps towards multi processing
nkrah a7434e5
Add test080_multiprocessing_1.py
nkrah 605192f
Add test030_dose_motion_dynamic_param_multiproc.py
nkrah e4bc3a7
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 523fdc9
Implement MultiProcessingHandler classes
nkrah cea24cf
create test080_multiprocessing_handler.py
nkrah ae37675
Implement import_data_from_actor_output()
nkrah 9c74aa2
Implement import_user_output_from_actor()
nkrah 87af53e
Implement import_user_output_from_actor in ActorBase
nkrah 196d954
Change local variable name in reassign_dynamic_params_for_process()
nkrah 138a44f
Implement FinalizeSimulation() in VoxelDepositActor
nkrah a796bec
Add simulation_id to SimulationOutput
nkrah 1375e4f
Implement SimulationOutput.store_output_from_simulation_engine()
nkrah fc90573
Simplify code in run_engine()
nkrah 91f6b7f
Implement SimulationMetaData class
nkrah 722552a
Use SimulationMetaData in Simulation
nkrah c7a317b
Update MultiProcessingHandlerBase class
nkrah 52bde4f
Remove obsolete generate_run_timing_interval_map() method
nkrah 3d1448b
Update imports in managers.py
nkrah fc0d155
Update run_in_process()
nkrah 8b43fb2
Store number_of_sub_processes and start_new_process in simulation_met…
nkrah a544da9
Introduce avoid_write_to_disk_in_subprocess kwarg in Simulation.run()
nkrah 19c9b17
Use multi_proc_handler in Simulation.run()
nkrah 23fb55e
Trigger import_user_output_from_actor() after multi_proc run
nkrah a1ce476
store meta_data after run
nkrah a120987
Get parameters from sources after multiproc run
nkrah 78bcd34
Remove obsolete code
nkrah 39a45c8
Trigger FinalizeSimulation() at the end of a run
nkrah 7e47bec
remove obsolete code
nkrah b8581ce
Add test008_dose_actor_multiproc.py
nkrah 3d4fe1e
Update test080_multiprocessing_1.py
nkrah dcebecc
Update GateObject to rename property 'warnings' in Simulation
nkrah c804709
Update run_engine to use Simulation.meta_data
nkrah 27b49c6
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 0a25f0d
Rename FinalizeSimulation() to EndOfMultiProcessAction()
nkrah c4cf4a4
Implement explicit inplace_merge_with in ItkImageDataItem
nkrah d94c0e4
Adapt merge_data to try to accelerate it (WIP)
nkrah 7d919d8
Implement sum_itk_images based on SimpleITK (workaround)
nkrah 7bfa8b7
remove debug prints and clean code
nkrah 11f6740
In BaseUserInterfaceToActorOutput.__getstate__: always use re…
nkrah 1383057
Implement reset_user_output() and reset_data()
nkrah 6bba1b7
remove debug print
nkrah 56061bc
Update comment
nkrah aebcc40
Update test008_dose_actor_multiproc.py
nkrah 557e679
Update test009_voxels_dynamic.py (not relevant for test result)
nkrah 15d72cd
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 53f5ff0
Correct typo in comment
nkrah 1463013
Implement DynamicGateObject.reassign_subset_of_dynamic_params()
nkrah b3e8f0c
Add attribute process_index to SimulationEngine (not used yet)
nkrah 0b7569b
First steps towards multi processing
nkrah d17682f
Add test080_multiprocessing_1.py
nkrah fb3cb56
Add test030_dose_motion_dynamic_param_multiproc.py
nkrah aa5e710
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 76fbfba
Implement MultiProcessingHandler classes
nkrah 6973f13
create test080_multiprocessing_handler.py
nkrah 0260522
Implement import_data_from_actor_output()
nkrah 3b93451
Implement import_user_output_from_actor()
nkrah 4d141c3
Implement import_user_output_from_actor in ActorBase
nkrah f06e627
Change local variable name in reassign_dynamic_params_for_process()
nkrah 3ea4bc7
Implement FinalizeSimulation() in VoxelDepositActor
nkrah 504673f
Add simulation_id to SimulationOutput
nkrah 76b0f86
Implement SimulationOutput.store_output_from_simulation_engine()
nkrah fd799dd
Simplify code in run_engine()
nkrah 3b6d94d
Implement SimulationMetaData class
nkrah c4cf0f0
Use SimulationMetaData in Simulation
nkrah 8b28b15
Update MultiProcessingHandlerBase class
nkrah b1f2d21
Remove obsolete generate_run_timing_interval_map() method
nkrah 2a033b7
Update imports in managers.py
nkrah 9a6f871
Update run_in_process()
nkrah 18b49a0
Store number_of_sub_processes and start_new_process in simulation_met…
nkrah 0a4b237
Introduce avoid_write_to_disk_in_subprocess kwarg in Simulation.run()
nkrah 805468a
Use multi_proc_handler in Simulation.run()
nkrah fa5ece3
Trigger import_user_output_from_actor() after multi_proc run
nkrah af06335
store meta_data after run
nkrah 002c000
Get parameters from sources after multiproc run
nkrah 43ae7d2
Remove obsolete code
nkrah 78eecbb
Trigger FinalizeSimulation() at the end of a run
nkrah c6b9ae1
remove obsolete code
nkrah d6d5b37
Add test008_dose_actor_multiproc.py
nkrah 53ceb61
Update test080_multiprocessing_1.py
nkrah 38896f0
Update GateObject to rename property 'warnings' in Simulation
nkrah 0e9928d
Update run_engine to use Simulation.meta_data
nkrah 0020307
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 2612857
Rename FinalizeSimulation() to EndOfMultiProcessAction()
nkrah 956be1c
Implement explicit inplace_merge_with in ItkImageDataItem
nkrah 7bb0000
Adapt merge_data to try to accelerate it (WIP)
nkrah d5c7c40
Implement sum_itk_images based on SimpleITK (workaround)
nkrah 481dbc4
remove debug prints and clean code
nkrah bffb06c
In BaseUserInterfaceToActorOutput.__getstate__: always use re…
nkrah fecd1e1
Implement reset_user_output() and reset_data()
nkrah 845544e
remove debug print
nkrah 2450ef5
Update comment
nkrah ee5b1df
Update test008_dose_actor_multiproc.py
nkrah 2f49d87
Update test009_voxels_dynamic.py (not relevant for test result)
nkrah 5ccba4e
Increment random_seed in run_in_process
nkrah 775ddb2
Extend inplace_merge_with() to accept *other, i.e. an unpackaged list
nkrah ccc141d
Fix ItkImageDataItem.inplace_merge_with()
nkrah 2df161a
Fix typo in error message
nkrah 5dcb80b
Update test008_dose_actor_multiproc.py
nkrah 79788b8
Deprecate unused kwarg 'stat' in assert_images()
nkrah 22411d4
Update multiproc logic in Simulation class
nkrah d21bcbf
Merge remote-tracking branch 'origin/multiproc' into multiproc
nkrah fb36286
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 27f4204
Implement reset_data() in DataItem base class
nkrah 994fded
update imports in dataitems.py
nkrah 1e706b4
Implement StatisticsDataItem
nkrah b17a98c
Implement StatisticsItemContainer
nkrah 09a95c4
Let SimulationStatisticsActor use new ActorOutputStatisticsActor
nkrah a2cd755
Implement ActorOutputStatisticsActor
nkrah abdaacd
Implement UserInterfaceToActorOutputStatisticsActor
nkrah 37b6bba
let default_suffix be an instance attribute of the ActorOutput classe…
nkrah 3b0e499
Implement ActorOutputUsingDataItemContainer.reset_data()
nkrah 6ce548c
Add process_cls(ActorOutputStatisticsActor)
nkrah fd4d7fc
Remove unused store_output_data() method
nkrah e1a6713
Update test008_dose_actor_multiproc.py
nkrah 3c4e7b5
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 51733c1
Update physics and sources documentation
dsarrut d76b64f
Add test080_multiprocessing_1.py
nkrah 98752bf
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 8217a0b
Implement MultiProcessingHandler classes
nkrah 3193890
create test080_multiprocessing_handler.py
nkrah 552fae4
Implement FinalizeSimulation() in VoxelDepositActor
nkrah 47bfa06
Add test008_dose_actor_multiproc.py
nkrah 352ac37
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] cb90f29
Rename FinalizeSimulation() to EndOfMultiProcessAction()
nkrah d4d0f4b
Update test008_dose_actor_multiproc.py
nkrah 8cb80b8
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 092dd69
Merge remote-tracking branch 'origin/master' into multiproc
nkrah ad36e56
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 216209f
rename test080 on multi processing to test082_xxx
nkrah 8063a4d
Add merge_root to processing.py
nkrah 3729d25
rename import_data_from_actor_output to merge_data_from_actor_output
nkrah fafbb32
Extend signature of import_user_output_from_actor by **kwargs
nkrah 69d9649
Add process_index attribute to SimulationEngine and SimulationOutput
nkrah 33fdb50
Implement clear_output_dir_before_run
nkrah 26d6c54
Implement sub_process_registry
nkrah 9fe4915
Make multi_proc_handler an instance attribute
nkrah e1d58bf
Add output_dir as argument to run_in_process()
nkrah a70ba52
Let each process store a json in the subfolder
nkrah f5f0d44
Capsulate code into merge_simulations_from_multiprocessing()
nkrah c9b9b66
check global variable __spec__ in run() to avoid breaking when runnin…
nkrah 43a8292
Remove merge_root() and unicity(): now in ActorOutputRoot class
nkrah facc182
Implement ActorOutputRootmerge_data_from_actor_output()
nkrah 5d06d5b
Add test019_phsp_actor_multiproc.py
nkrah 01d0ea5
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 245b73b
Remove obsolete imports in processing.py
nkrah aaed7a5
Add property counts to SimulationStatisticsActor
nkrah c70cfef
remove obsolete UserInterfaceToActorOutputStatisticsActor
nkrah f16c1ea
Extend DataItem.__getattr__ to get attributes from self.data if possible
nkrah 3423476
Adapt read_stat_file_legacy() to updated stats actor
nkrah fc7322a
Adapt assert_stats() and assert_stats_json() to updated stats actor
nkrah a8f9add
Merge sim_start_time and sim_stop_time via min/max
nkrah 2210788
Adapt assert_stats_json() to updated StatsActor
nkrah d482c62
Improve handling of start_time and stop_time in StatisticsDataItem
nkrah 1473df0
Update GateSimulationStatisticsActor::GetCounts()
nkrah 014e950
In GateSimulationStatisticsActor: save start_time and stop_time as ep…
nkrah 451e7da
adapt read_stat_file_json() to updated StatsActor
nkrah f6f348b
remove redundant code in test008_dose_actor_multiproc.py
nkrah 09b4830
Merge remote-tracking branch 'origin/master' into multiproc
nkrah 9e69420
[pre-commit.ci] Automatic python and c++ formatting
pre-commit-ci[bot] 0eb6b81
activate ssh session on github
nkrah bbec500
update test082_multiprocessing_1.py
nkrah ec56329
pick up simulation_id as meta_data after a simulation
nkrah 039ef82
add explicit process_cls() for MultiProcessHandler classes
nkrah dd3068c
Update file names in test081_simulation_optigan_with_random_seed.py
nkrah 0ac5519
Adapt test006_runs.py to updated StatsActorOutput
nkrah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
opengate/tests/src/test030_dose_motion_dynamic_param_multiproc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import opengate as gate | ||
from scipy.spatial.transform import Rotation | ||
from opengate.tests import utility | ||
|
||
if __name__ == "__main__": | ||
paths = utility.get_default_test_paths( | ||
__file__, "gate_test029_volume_time_rotation", "test030" | ||
) | ||
|
||
# create the simulation | ||
sim = gate.Simulation() | ||
|
||
# main options | ||
sim.g4_verbose = False | ||
sim.visu = False | ||
sim.random_seed = 983456 | ||
sim.output_dir = paths.output | ||
|
||
# units | ||
m = gate.g4_units.m | ||
mm = gate.g4_units.mm | ||
cm = gate.g4_units.cm | ||
um = gate.g4_units.um | ||
nm = gate.g4_units.nm | ||
MeV = gate.g4_units.MeV | ||
Bq = gate.g4_units.Bq | ||
sec = gate.g4_units.second | ||
|
||
# change world size | ||
sim.world.size = [1 * m, 1 * m, 1 * m] | ||
|
||
# add a simple fake volume to test hierarchy | ||
# translation and rotation like in the Gate macro | ||
fake = sim.add_volume("Box", "fake") | ||
fake.size = [40 * cm, 40 * cm, 40 * cm] | ||
fake.translation = [1 * cm, 2 * cm, 3 * cm] | ||
fake.material = "G4_AIR" | ||
fake.color = [1, 0, 1, 1] | ||
|
||
# waterbox | ||
waterbox = sim.add_volume("Box", "waterbox") | ||
waterbox.mother = fake | ||
waterbox.size = [20 * cm, 20 * cm, 20 * cm] | ||
waterbox.translation = [-3 * cm, -2 * cm, -1 * cm] | ||
waterbox.rotation = Rotation.from_euler("y", -20, degrees=True).as_matrix() | ||
waterbox.material = "G4_WATER" | ||
waterbox.color = [0, 0, 1, 1] | ||
|
||
# physics | ||
sim.physics_manager.set_production_cut("world", "all", 700 * um) | ||
|
||
# default source for tests | ||
# the source is fixed at the center, only the volume will move | ||
source = sim.add_source("GenericSource", "mysource") | ||
source.energy.mono = 150 * MeV | ||
source.particle = "proton" | ||
source.position.type = "disc" | ||
source.position.radius = 5 * mm | ||
source.direction.type = "momentum" | ||
source.direction.momentum = [0, 0, 1] | ||
source.activity = 30000 * Bq | ||
|
||
# add dose actor | ||
dose = sim.add_actor("DoseActor", "dose") | ||
dose.output_filename = "test030.mhd" | ||
dose.attached_to = waterbox | ||
dose.size = [99, 99, 99] | ||
mm = gate.g4_units.mm | ||
dose.spacing = [2 * mm, 2 * mm, 2 * mm] | ||
dose.translation = [2 * mm, 3 * mm, -2 * mm] | ||
dose.edep.keep_data_per_run = True | ||
dose.edep.auto_merge = True | ||
dose.edep_uncertainty.active = True | ||
|
||
# add stat actor | ||
stats = sim.add_actor("SimulationStatisticsActor", "Stats") | ||
|
||
# motion | ||
n = 3 | ||
interval_length = 1 * sec / n | ||
sim.run_timing_intervals = [ | ||
(i * interval_length, (i + 1) * interval_length) for i in range(n) | ||
] | ||
gantry_angles_deg = [i * 20 for i in range(n)] | ||
( | ||
dynamic_translations, | ||
dynamic_rotations, | ||
) = gate.geometry.utility.get_transform_orbiting( | ||
initial_position=fake.translation, axis="Y", angle_deg=gantry_angles_deg | ||
) | ||
fake.add_dynamic_parametrisation( | ||
translation=dynamic_translations, rotation=dynamic_rotations | ||
) | ||
|
||
# start simulation | ||
sim.run(number_of_sub_processes=3 * len(sim.run_timing_intervals)) | ||
|
||
# # print results at the end | ||
# print(stats) | ||
# | ||
# # tests | ||
# stats_ref = utility.read_stat_file(paths.output_ref / "stats030.txt") | ||
# is_ok = utility.assert_stats(stats, stats_ref, 0.11) | ||
# | ||
# print() | ||
# gate.exception.warning("Difference for EDEP") | ||
# is_ok = ( | ||
# utility.assert_images( | ||
# paths.output_ref / "test030-edep.mhd", | ||
# dose.edep.get_output_path(), | ||
# stats, | ||
# tolerance=30, | ||
# ignore_value=0, | ||
# ) | ||
# and is_ok | ||
# ) | ||
# | ||
# print("\nDifference for uncertainty") | ||
# is_ok = ( | ||
# utility.assert_images( | ||
# paths.output_ref / "test030-edep_uncertainty.mhd", | ||
# dose.edep_uncertainty.get_output_path(), | ||
# stats, | ||
# tolerance=15, | ||
# ignore_value=1, | ||
# ) | ||
# and is_ok | ||
# ) | ||
# | ||
# utility.test_ok(is_ok) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
from opengate.utility import g4_units | ||
import opengate as gate | ||
from opengate.tests.utility import get_default_test_paths | ||
|
||
|
||
if __name__ == "__main__": | ||
paths = get_default_test_paths(__file__, output_folder="test080") | ||
|
||
s = g4_units.s | ||
|
||
sim = gate.Simulation() | ||
sim.run_timing_intervals = [[0 * s, 1 * s], [1 * s, 3 * s], [10 * s, 15 * s]] | ||
sim.output_dir = paths.output | ||
|
||
box1 = sim.add_volume("BoxVolume", "box1") | ||
box1.add_dynamic_parametrisation( | ||
translation=[[i, i, i] for i in range(len(sim.run_timing_intervals))] | ||
) | ||
|
||
n_proc = 4 * len(sim.run_timing_intervals) | ||
run_timing_interval_map = sim.generate_run_timing_interval_map(n_proc) | ||
print(run_timing_interval_map) | ||
|
||
output = sim.run(number_of_sub_processes=n_proc) | ||
|
||
print("*** output ***") | ||
for o in output: | ||
print(o) | ||
|
||
print(f"ID of the main sim: {id(sim)}") | ||
|
||
ids = [e[2] for e in output] | ||
assert id(sim) not in ids |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why ? I thought we just divide ALL time_interval by the number_of_processes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but letting the user define the total number of processes rather than the process per run is more intuitive and will not require an API change if we implement a more advanced splitting scheme in the future. So I think it's better this way.