Skip to content

Commit

Permalink
created tests for tps source
Browse files Browse the repository at this point in the history
Treatment plan source file was missing from the branch. Added.
small modifications. Still trying to figure out the error in spot positions
Fixed bug with TPS rotation and created tests
Removed old version of the helpers. Now the function that reads the treatment plan txt file returns also the gantry angle
Created tests for: optics in air, absolute dose in water and gantry rotation.
Working version of TPSource
Removed full MA polinomia from the beamline model
added test for weights and comparison pbs-tps
exposed G4UserLimits and StepLimiter
Corrected bugs in TPSource and created working tests for optics, absolute dose, ranges and weights
Improved test metrics and TPS readability
test optics in vbl
Refactored TPS init and renamed beamline properties
changed TPS initialization
minor changes, mainly estetics'
turn off visualization
 reduced the size of the detectors
Further reduced the detector's side
Included energy spread in the TPS model and examples
Corrected inconsistency in test for absolute dose. Added function to test dose grid shape and spacing to helpers_test
accounted for correction in dose grid (PR#137)
accounted for PR#137
corrected scale_dose function for case image size 1,1,x
multiprocessing: do we need a timeout in p.join()?
spot weighted on the beamset number of particles, not on the beam ones.
created separate neme dictionary for particles to use in user_limit
Changed queue initialization for multiprocessing
added check to avoid error when beam spot has almost zero weight
removed step limiter from branch
modified threshold
  • Loading branch information
Martina Favaretto authored and tbaudier committed Jun 30, 2023
1 parent 2423a50 commit b75e965
Show file tree
Hide file tree
Showing 12 changed files with 2,386 additions and 9 deletions.
37 changes: 34 additions & 3 deletions opengate/SimulationEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
import sys
import os
from .ExceptionHandler import *
from multiprocessing import Process, set_start_method, Queue
from multiprocessing import (
Process,
set_start_method,
Manager,
Queue,
active_children,
cpu_count,
)
from opengate_core import G4RunManagerFactory
from .Decorators import requires_fatal
from .helpers import fatal, warning
Expand Down Expand Up @@ -131,12 +138,28 @@ def start(self):
# (the "force" option is needed for notebooks)
set_start_method("fork", force=True)
# set_start_method("spawn")
q = Queue()
q = Manager().Queue()
# q = Queue()
p = Process(target=self.init_and_start, args=(q,))
print(f"Active children: {len(active_children())}")
print(f"CPU count: {cpu_count()}")
print(f"Queue full: {q.full()}")
print("---start process---")
p.start()
import time

print(f"Active children: {len(active_children())}")
print(f"CPU count: {cpu_count()}")
print(f"Queue full: {q.full()}")
while len(active_children()) >= cpu_count() + 4:
print(f"Active children: {len(active_children())}")
print(f"CPU count: {cpu_count()}")
time.sleep(0.01)
print(q.full())
self.state = "started"
p.join()
p.join() # (timeout=10) # timeout might be needed
self.state = "after"
print("AFTER")
output = q.get()
else:
output = self.init_and_start(None)
Expand Down Expand Up @@ -184,7 +207,15 @@ def init_and_start(self, queue):
output.store_hook_log(self)
output.current_random_seed = self.current_random_seed
if queue is not None:
print("--- in process, before put ---")
print(f"Active children: {len(active_children())}")
print(f"CPU count: {cpu_count()}")
print(f"Queue full: {queue.full()}")
queue.put(output)
print("--- in process, after put ---")
print(f"Active children: {len(active_children())}")
print(f"CPU count: {cpu_count()}")
print(f"Queue full: {queue.full()}")
return None
else:
return output
Expand Down
3 changes: 3 additions & 0 deletions opengate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
from .helpers_tests import *
from .helpers_tests_root import *
from .helpers_transform import *
from .helpers_beamline import *
from .helpers_rt_plan import *

# main mechanism for the 'elements': source, actor, volume
from .UserInfo import *
from .UserElement import *
from .source.SourceBase import *
from .actor.ActorBase import *
from .geometry.VolumeBase import *
from .source.TreatmentPlanSource import *

# main object
from .Simulation import *
Expand Down
69 changes: 69 additions & 0 deletions opengate/helpers_beamline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# N.B: distances in mm, degrees in rad


class Rashi:
pass


class RangeMod:
pass


class BeamlineModel:
def __init__(self):
self.name = None
self.radiation_types = []
self.rm = None # range modulator
self.rashi = None
# Nozzle entrance to Isocenter distance
self.distance_nozzle_iso = 0 # mm
# SMX (X bending magnet) to Isocenter distance
self.distance_stearmag_to_isocenter_x = float(
"inf"
) # default infinity for parallel beams
# SMY (Y bending magnet) to Isocenter distance
self.distance_stearmag_to_isocenter_y = float("inf")
# polinomial coefficients
self.energy_mean_coeffs = [0]
self.energy_spread_coeffs = [0]
self.sigma_x_coeffs = [0]
self.theta_x_coeffs = [0]
self.epsilon_x_coeffs = [0]
self.sigma_y_coeffs = [0]
self.theta_y_coeffs = [0]
self.epsilon_y_coeffs = [0]
# convergence
self.conv_x = 0
self.conv_y = 0

def _polynomial_map(self, base, coeff):
# coeff are given with decreasing degree (coeff[0]->max degree)
polyDegree = len(coeff)
exp = list(range(polyDegree))
exp.reverse()

return sum([c * (base ** (i)) for c, i in zip(coeff, exp)])

def get_energy(self, nominal_energy):
return self._polynomial_map(nominal_energy, self.energy_mean_coeffs)

def get_sigma_energy(self, nominal_energy):
return self._polynomial_map(nominal_energy, self.energy_spread_coeffs)

def get_sigma_x(self, energy):
return self._polynomial_map(energy, self.sigma_x_coeffs)

def get_theta_x(self, energy):
return self._polynomial_map(energy, self.theta_x_coeffs)

def get_epsilon_x(self, energy):
return self._polynomial_map(energy, self.epsilon_x_coeffs)

def get_sigma_y(self, energy):
return self._polynomial_map(energy, self.sigma_y_coeffs)

def get_theta_y(self, energy):
return self._polynomial_map(energy, self.theta_y_coeffs)

def get_epsilon_y(self, energy):
return self._polynomial_map(energy, self.epsilon_y_coeffs)
Loading

0 comments on commit b75e965

Please sign in to comment.