AOT-biomaps 2.9.186__py3-none-any.whl → 2.9.294__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of AOT-biomaps might be problematic. Click here for more details.

Files changed (28) hide show
  1. AOT_biomaps/AOT_Acoustic/StructuredWave.py +2 -2
  2. AOT_biomaps/AOT_Acoustic/_mainAcoustic.py +11 -6
  3. AOT_biomaps/AOT_Experiment/Tomography.py +74 -4
  4. AOT_biomaps/AOT_Experiment/_mainExperiment.py +95 -55
  5. AOT_biomaps/AOT_Recon/AOT_Optimizers/DEPIERRO.py +48 -13
  6. AOT_biomaps/AOT_Recon/AOT_Optimizers/LS.py +406 -13
  7. AOT_biomaps/AOT_Recon/AOT_Optimizers/MAPEM.py +118 -38
  8. AOT_biomaps/AOT_Recon/AOT_Optimizers/MLEM.py +303 -102
  9. AOT_biomaps/AOT_Recon/AOT_Optimizers/PDHG.py +443 -12
  10. AOT_biomaps/AOT_Recon/AOT_PotentialFunctions/RelativeDifferences.py +10 -14
  11. AOT_biomaps/AOT_Recon/AOT_SparseSMatrix/SparseSMatrix_CSR.py +274 -0
  12. AOT_biomaps/AOT_Recon/AOT_SparseSMatrix/SparseSMatrix_SELL.py +328 -0
  13. AOT_biomaps/AOT_Recon/AOT_SparseSMatrix/__init__.py +2 -0
  14. AOT_biomaps/AOT_Recon/AOT_biomaps_kernels.cubin +0 -0
  15. AOT_biomaps/AOT_Recon/AlgebraicRecon.py +243 -113
  16. AOT_biomaps/AOT_Recon/AnalyticRecon.py +26 -41
  17. AOT_biomaps/AOT_Recon/BayesianRecon.py +81 -146
  18. AOT_biomaps/AOT_Recon/PrimalDualRecon.py +157 -94
  19. AOT_biomaps/AOT_Recon/ReconEnums.py +27 -2
  20. AOT_biomaps/AOT_Recon/ReconTools.py +229 -12
  21. AOT_biomaps/AOT_Recon/__init__.py +1 -0
  22. AOT_biomaps/AOT_Recon/_mainRecon.py +60 -53
  23. AOT_biomaps/__init__.py +4 -69
  24. {aot_biomaps-2.9.186.dist-info → aot_biomaps-2.9.294.dist-info}/METADATA +2 -1
  25. aot_biomaps-2.9.294.dist-info/RECORD +47 -0
  26. aot_biomaps-2.9.186.dist-info/RECORD +0 -43
  27. {aot_biomaps-2.9.186.dist-info → aot_biomaps-2.9.294.dist-info}/WHEEL +0 -0
  28. {aot_biomaps-2.9.186.dist-info → aot_biomaps-2.9.294.dist-info}/top_level.txt +0 -0
@@ -51,56 +51,41 @@ class AnalyticRecon(Recon):
51
51
  def _iFourierRecon(self, AOsignal):
52
52
  """
53
53
  Reconstruction d'image utilisant la transformation de Fourier inverse.
54
-
55
- :param AOsignal: Signal dans le domaine temporel.
54
+ :param AOsignal: Signal dans le domaine temporel (shape: N_t, N_theta).
56
55
  :return: Image reconstruite dans le domaine spatial.
57
56
  """
58
- # Signal dans le domaine fréquentiel (FFT sur l'axe temporel)
59
- s_tilde = np.fft.fft(AOsignal, axis=0)
60
-
61
- theta = np.array([af.angle for af in self.experiment.AcousticFields]) # angles (N_theta,)
62
- f_s = np.array([af.f_s for af in self.experiment.AcousticFields]) # spatial freqs (N_theta,)
63
- f_t = np.fft.fftfreq(AOsignal.shape[0], d=self.experiment.dt) # temporal freqs
64
-
57
+ theta = np.array([af.angle for af in self.experiment.AcousticFields])
58
+ f_s = np.array([af.f_s for af in self.experiment.AcousticFields])
59
+ dt = self.experiment.dt
60
+ f_t = np.fft.fftfreq(AOsignal.shape[0], d=dt) # fréquences temporelles
65
61
  x = self.experiment.OpticImage.laser.x
66
62
  z = self.experiment.OpticImage.laser.z
67
- X, Z = np.meshgrid(x, z, indexing='ij') # shape (Nx, Nz)
68
-
69
- N_theta = len(theta)
70
- I_rec = np.zeros((len(x), len(z)), dtype=complex)
71
-
72
- for i, th in enumerate(trange(N_theta, desc="AOT-BioMaps -- Analytic Recontruction Tomography : iFourier (Processing projection) ---- processing on single CPU ----")):
73
- fs = f_s[i]
74
-
75
- # Projection des coordonnées dans le repère tourné
76
- x_prime = X * np.cos(th) + Z * np.sin(th)
77
- z_prime = -X * np.sin(th) + Z * np.cos(th)
78
-
79
- # Signal spectral pour cet angle (1D pour chaque f_t)
80
- s_angle = s_tilde[:, i] # shape (len(f_t),)
63
+ X, Z = np.meshgrid(x, z, indexing='ij') # grille spatiale (Nx, Nz)
81
64
 
82
- # Grille 2D des fréquences
83
- F_t, F_s = np.meshgrid(f_t, [fs], indexing='ij') # F_t: (len(f_t), 1), F_s: (1, 1)
65
+ # Transformée de Fourier du signal
66
+ s_tilde = np.fft.fft(AOsignal, axis=0) # shape: (N_t, N_theta)
84
67
 
85
- # Phase : exp(2iπ(x' f_s + z' f_t)) = (x_prime * f_s + z_prime * f_t)
86
- phase = 2j * np.pi * (x_prime[:, :, None] * fs + z_prime[:, :, None] * f_t[None, None, :])
87
-
88
- # reshape s_angle to (len(f_t), 1, 1)
89
- s_angle = s_angle[:, None, None]
90
-
91
- # Contribution de cet angle
92
- integrand = s_angle * np.exp(phase)
93
-
94
- # Intégration sur f_t (somme discrète)
95
- I_theta = np.sum(integrand, axis=0)
96
-
97
- # Ajout à la reconstruction
98
- I_rec += I_theta
99
-
100
- I_rec /= N_theta
68
+ # Initialisation de l'image reconstruite
69
+ I_rec = np.zeros((len(x), len(z)), dtype=complex)
101
70
 
71
+ # Boucle sur les angles
72
+ for i, th in enumerate(trange(len(theta), desc="AOT-BioMaps -- iFourier Reconstruction")):
73
+ # Coordonnées tournées
74
+ X_prime = X * np.cos(th) + Z * np.sin(th)
75
+ Z_prime = -X * np.sin(th) + Z * np.cos(th)
76
+
77
+ # Pour chaque fréquence temporelle f_t[j]
78
+ for j in range(len(f_t)):
79
+ # Phase: exp(2jπ (X_prime * f_s[i] + Z_prime * f_t[j]))
80
+ phase = 2j * np.pi * (X_prime * f_s[i] + Z_prime * f_t[j])
81
+ # Contribution de cette fréquence
82
+ I_rec += s_tilde[j, i] * np.exp(phase) * dt # Pondération par dt pour l'intégration
83
+
84
+ # Normalisation
85
+ I_rec /= len(theta)
102
86
  return np.abs(I_rec)
103
87
 
88
+
104
89
  def _iRadonRecon(self, AOsignal):
105
90
  """
106
91
  Reconstruction d'image utilisant la méthode iRadon.
@@ -1,7 +1,7 @@
1
1
  from AOT_biomaps.AOT_Recon.AlgebraicRecon import AlgebraicRecon
2
2
  from AOT_biomaps.AOT_Recon.ReconEnums import ReconType, OptimizerType, PotentialType, ProcessType
3
3
  from .ReconTools import check_gpu_memory, calculate_memory_requirement
4
- from .AOT_Optimizers import MAPEM, DEPIERRO
4
+ from .AOT_Optimizers import MAPEM, MAPEM_STOP, DEPIERRO
5
5
  from AOT_biomaps.Config import config
6
6
 
7
7
  import warnings
@@ -66,25 +66,18 @@ class BayesianRecon(AlgebraicRecon):
66
66
  dir_name += f'_Beta_{self.beta}_Sigma_{self.sigma}'
67
67
 
68
68
  results_dir = os.path.join(self.saveDir, dir_name)
69
+ if not os.path.exists(results_dir):
70
+ os.makedirs(results_dir)
69
71
 
70
- if os.path.exists(results_dir):
72
+ if os.path.exists(os.path.join(results_dir,"indices.npy")):
71
73
  return (True, results_dir)
72
74
 
73
75
  return (False, results_dir)
74
76
 
75
- def load(self, withTumor=True, results_date=None, optimizer=None, potential_function=None, beta=None, delta=None, gamma=None, sigma=None, filePath=None):
77
+ def load(self, withTumor=True, results_date=None, optimizer=None, potential_function=None, filePath=None, show_logs=True):
76
78
  """
77
- Load the reconstruction results and indices for Bayesian reconstruction and store them in self.
78
- Args:
79
- withTumor (bool): If True, loads the reconstruction with tumor; otherwise, loads the reconstruction without tumor.
80
- results_date (str): Date string (format "ddmm") to specify which results to load. If None, uses the most recent date in saveDir.
81
- optimizer (OptimizerType): Optimizer type to filter results. If None, uses the current optimizer of the instance.
82
- potential_function (PotentialType): Potential function type to filter results. If None, uses the current potential function of the instance.
83
- beta (float): Beta parameter to match the saved directory. If None, skips this filter.
84
- delta (float): Delta parameter to match the saved directory. If None, skips this filter.
85
- gamma (float): Gamma parameter to match the saved directory. If None, skips this filter.
86
- sigma (float): Sigma parameter to match the saved directory. If None, skips this filter.
87
- filePath (str): Optional. If provided, loads directly from this path (overrides saveDir and results_date).
79
+ Load the reconstruction results and indices as lists of 2D np arrays for Bayesian reconstruction and store them in self.
80
+ If the loaded file is a 3D array, it is split into a list of 2D arrays.
88
81
  """
89
82
  if filePath is not None:
90
83
  # Mode chargement direct depuis un fichier
@@ -92,53 +85,55 @@ class BayesianRecon(AlgebraicRecon):
92
85
  recon_path = filePath
93
86
  if not os.path.exists(recon_path):
94
87
  raise FileNotFoundError(f"No reconstruction file found at {recon_path}.")
95
-
96
- if withTumor:
97
- self.reconPhantom = np.load(recon_path, allow_pickle=True)
88
+ # Charge le fichier (3D ou liste de 2D)
89
+ data = np.load(recon_path, allow_pickle=True)
90
+ # Découpe en liste de 2D si c'est un tableau 3D
91
+ if isinstance(data, np.ndarray) and data.ndim == 3:
92
+ if withTumor:
93
+ self.reconPhantom = [data[i, :, :] for i in range(data.shape[0])]
94
+ else:
95
+ self.reconLaser = [data[i, :, :] for i in range(data.shape[0])]
98
96
  else:
99
- self.reconLaser = np.load(recon_path, allow_pickle=True)
100
-
101
- # Essayer de charger les indices (fichier avec suffixe "_indices.npy")
102
- base_dir, file_name = os.path.split(recon_path)
103
- file_base, _ = os.path.splitext(file_name)
104
- indices_path = os.path.join(base_dir, f"{file_base}_indices.npy")
97
+ # Sinon, suppose que c'est déjà une liste de 2D
98
+ if withTumor:
99
+ self.reconPhantom = data
100
+ else:
101
+ self.reconLaser = data
102
+ # Essayer de charger les indices
103
+ base_dir, _ = os.path.split(recon_path)
104
+ indices_path = os.path.join(base_dir, 'indices.npy')
105
105
  if os.path.exists(indices_path):
106
- self.indices = np.load(indices_path, allow_pickle=True)
107
- else:
108
- indices_path = os.path.join(base_dir, 'reconIndices.npy') # Alternative
109
- if os.path.exists(indices_path):
110
- self.indices = np.load(indices_path, allow_pickle=True)
106
+ indices_data = np.load(indices_path, allow_pickle=True)
107
+ if isinstance(indices_data, np.ndarray) and indices_data.ndim == 3:
108
+ self.indices = [indices_data[i, :, :] for i in range(indices_data.shape[0])]
111
109
  else:
112
- self.indices = None
113
-
114
- print(f"Loaded reconstruction results and indices from {recon_path}")
110
+ self.indices = indices_data
111
+ else:
112
+ self.indices = None
113
+ if show_logs:
114
+ print(f"Loaded reconstruction results and indices from {recon_path}")
115
115
  else:
116
116
  # Mode chargement depuis le répertoire de résultats
117
117
  if self.saveDir is None:
118
118
  raise ValueError("Save directory is not specified. Please set saveDir before loading.")
119
-
120
119
  # Use current optimizer and potential function if not provided
121
120
  opt_name = optimizer.value if optimizer is not None else self.optimizer.value
122
121
  pot_name = potential_function.value if potential_function is not None else self.potentialFunction.value
123
-
124
122
  # Build the base directory pattern
125
123
  dir_pattern = f'results_*_{opt_name}_{pot_name}'
126
-
127
124
  # Add parameters to the pattern based on the optimizer
128
125
  if optimizer is None:
129
126
  optimizer = self.optimizer
130
-
131
127
  if optimizer == OptimizerType.PPGMLEM:
132
- beta_str = f'_Beta_{beta if beta is not None else self.beta}'
133
- delta_str = f'_Delta_{delta if delta is not None else self.delta}'
134
- gamma_str = f'_Gamma_{gamma if gamma is not None else self.gamma}'
135
- sigma_str = f'_Sigma_{sigma if sigma is not None else self.sigma}'
128
+ beta_str = f'_Beta_{self.beta}'
129
+ delta_str = f'_Delta_{self.delta}'
130
+ gamma_str = f'_Gamma_{self.gamma}'
131
+ sigma_str = f'_Sigma_{self.sigma}'
136
132
  dir_pattern += f'{beta_str}{delta_str}{gamma_str}{sigma_str}'
137
133
  elif optimizer in (OptimizerType.PGC, OptimizerType.DEPIERRO95):
138
- beta_str = f'_Beta_{beta if beta is not None else self.beta}'
139
- sigma_str = f'_Sigma_{sigma if sigma is not None else self.sigma}'
134
+ beta_str = f'_Beta_{self.beta}'
135
+ sigma_str = f'_Sigma_{self.sigma}'
140
136
  dir_pattern += f'{beta_str}{sigma_str}'
141
-
142
137
  # Find the most recent results directory if no date is specified
143
138
  if results_date is None:
144
139
  dirs = [d for d in os.listdir(self.saveDir) if os.path.isdir(os.path.join(self.saveDir, d)) and dir_pattern in d]
@@ -149,33 +144,40 @@ class BayesianRecon(AlgebraicRecon):
149
144
  else:
150
145
  results_dir = os.path.join(self.saveDir, f'results_{results_date}_{opt_name}_{pot_name}')
151
146
  if optimizer == OptimizerType.PPGMLEM:
152
- results_dir += f'_Beta_{beta if beta is not None else self.beta}_Delta_{delta if delta is not None else self.delta}_Gamma_{gamma if gamma is not None else self.gamma}_Sigma_{sigma if sigma is not None else self.sigma}'
147
+ results_dir += f'_Beta_{self.beta}_Delta_{self.delta}_Gamma_{self.gamma}_Sigma_{self.sigma}'
153
148
  elif optimizer in (OptimizerType.PGC, OptimizerType.DEPIERRO95):
154
- results_dir += f'_Beta_{beta if beta is not None else self.beta}_Sigma_{sigma if sigma is not None else self.sigma}'
149
+ results_dir += f'_Beta_{self.beta}_Sigma_{self.sigma}'
155
150
  if not os.path.exists(results_dir):
156
151
  raise FileNotFoundError(f"Directory {results_dir} does not exist.")
157
-
158
152
  # Load reconstruction results
159
153
  recon_key = 'reconPhantom' if withTumor else 'reconLaser'
160
154
  recon_path = os.path.join(results_dir, f'{recon_key}.npy')
161
155
  if not os.path.exists(recon_path):
162
156
  raise FileNotFoundError(f"No reconstruction file found at {recon_path}.")
163
-
164
- if withTumor:
165
- self.reconPhantom = np.load(recon_path, allow_pickle=True)
157
+ data = np.load(recon_path, allow_pickle=True)
158
+ if isinstance(data, np.ndarray) and data.ndim == 3:
159
+ if withTumor:
160
+ self.reconPhantom = [data[i, :, :] for i in range(data.shape[0])]
161
+ else:
162
+ self.reconLaser = [data[i, :, :] for i in range(data.shape[0])]
166
163
  else:
167
- self.reconLaser = np.load(recon_path, allow_pickle=True)
168
-
169
- # Load saved indices
170
- indices_path = os.path.join(results_dir, 'reconIndices.npy')
164
+ if withTumor:
165
+ self.reconPhantom = data
166
+ else:
167
+ self.reconLaser = data
168
+ # Load saved indices as list of 2D arrays
169
+ indices_path = os.path.join(results_dir, 'indices.npy')
171
170
  if not os.path.exists(indices_path):
172
171
  raise FileNotFoundError(f"No indices file found at {indices_path}.")
172
+ indices_data = np.load(indices_path, allow_pickle=True)
173
+ if isinstance(indices_data, np.ndarray) and indices_data.ndim == 3:
174
+ self.indices = [indices_data[i, :, :] for i in range(indices_data.shape[0])]
175
+ else:
176
+ self.indices = indices_data
177
+ if show_logs:
178
+ print(f"Loaded reconstruction results and indices from {results_dir}")
173
179
 
174
- self.indices = np.load(indices_path, allow_pickle=True)
175
-
176
- print(f"Loaded reconstruction results and indices from {results_dir}")
177
-
178
- def run(self, processType=ProcessType.PYTHON, withTumor=True):
180
+ def run(self, processType=ProcessType.PYTHON, withTumor=True, show_logs=True):
179
181
  """
180
182
  This method is a placeholder for the Bayesian reconstruction process.
181
183
  It currently does not perform any operations but serves as a template for future implementations.
@@ -187,109 +189,42 @@ class BayesianRecon(AlgebraicRecon):
187
189
  else:
188
190
  raise ValueError(f"Unknown Bayesian reconstruction type: {processType}")
189
191
 
190
- def _bayesianReconCASToR(self, withTumor):
192
+ def _bayesianReconCASToR(self, show_logs, withTumor):
191
193
  raise NotImplementedError("CASToR Bayesian reconstruction is not implemented yet.")
192
194
 
193
- def _bayesianReconPython(self, withTumor):
194
-
195
+ def _bayesianReconPython(self, show_logs, withTumor):
195
196
  if withTumor:
196
197
  if self.experiment.AOsignal_withTumor is None:
197
198
  raise ValueError("AO signal with tumor is not available. Please generate AO signal with tumor the experiment first in the experiment object.")
198
199
  if self.optimizer.value == OptimizerType.PPGMLEM.value:
199
- self.reconPhantom, self.indices = self._MAPEM_STOP(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withTumor, withTumor=withTumor)
200
+ self.reconPhantom, self.indices = MAPEM_STOP(
201
+ SMatrix=self.SMatrix,
202
+ y=self.experiment.AOsignal_withTumor,
203
+ Omega=self.potentialFunction,
204
+ beta=self.beta,
205
+ delta=self.delta,
206
+ gamma=self.gamma,
207
+ sigma=self.sigma,
208
+ numIterations=self.numIterations,
209
+ isSavingEachIteration=self.isSavingEachIteration,
210
+ withTumor=withTumor,
211
+ device=self.device,
212
+ max_saves=5000,
213
+ show_logs=True)
200
214
  elif self.optimizer.value == OptimizerType.PGC.value:
201
- self.reconPhantom, self.indices = self._MAPEM(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withTumor, withTumor=withTumor)
215
+ self.reconPhantom, self.indices = MAPEM(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withTumor, withTumor=withTumor, show_logs=show_logs)
202
216
  elif self.optimizer.value == OptimizerType.DEPIERRO95.value:
203
- self.reconPhantom, self.indices = self._DEPIERRO(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withTumor, withTumor=withTumor)
217
+ self.reconPhantom, self.indices = DEPIERRO(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withTumor, withTumor=withTumor, show_logs=show_logs)
204
218
  else:
205
219
  raise ValueError(f"Unknown optimizer type: {self.optimizer.value}")
206
220
  else:
207
221
  if self.experiment.AOsignal_withoutTumor is None:
208
222
  raise ValueError("AO signal without tumor is not available. Please generate AO signal without tumor the experiment first in the experiment object.")
209
223
  if self.optimizer.value == OptimizerType.PPGMLEM.value:
210
- self.reconLaser, self.indices = self._MAPEM_STOP(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withoutTumor, withTumor=withTumor)
224
+ self.reconLaser, self.indices = MAPEM_STOP(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withoutTumor, withTumor=withTumor, show_logs=show_logs)
211
225
  elif self.optimizer.value == OptimizerType.PGC.value:
212
- self.reconLaser, self.indices = self._MAPEM(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withoutTumor, withTumor=withTumor)
226
+ self.reconLaser, self.indices = MAPEM(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withoutTumor, withTumor=withTumor, show_logs=show_logs)
213
227
  elif self.optimizer.value == OptimizerType.DEPIERRO95.value:
214
- self.reconLaser, self.indices = self._DEPIERRO(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withoutTumor, withTumor=withTumor)
228
+ self.reconLaser, self.indices = DEPIERRO(SMatrix=self.SMatrix, y=self.experiment.AOsignal_withoutTumor, withTumor=withTumor, show_logs=show_logs)
215
229
  else:
216
- raise ValueError(f"Unknown optimizer type: {self.optimizer.value}")
217
-
218
- def _MAPEM_STOP(self, SMatrix, y, withTumor):
219
- """
220
- This method implements the MAPEM_STOP algorithm using either CPU or single-GPU PyTorch acceleration.
221
- Multi-GPU and Multi-CPU modes are not implemented for this algorithm.
222
- """
223
- result = None
224
- required_memory = calculate_memory_requirement(SMatrix, y)
225
-
226
- if self.isGPU:
227
- if check_gpu_memory(config.select_best_gpu(), required_memory):
228
- try:
229
- result = MAPEM._MAPEM_GPU_STOP(SMatrix=SMatrix, y=y, Omega=self.potentialFunction, numIterations=self.numIterations, beta=self.beta, delta=self.delta, gamma=self.gamma, sigma=self.sigma, isSavingEachIteration=self.isSavingEachIteration, withTumor=withTumor)
230
- except Exception as e:
231
- warnings.warn(f"Falling back to CPU implementation due to an error in GPU implementation: {e}")
232
- else:
233
- warnings.warn("Insufficient GPU memory for single GPU MAPEM_STOP. Falling back to CPU.")
234
-
235
- if result is None:
236
- try:
237
- result = MAPEM._MAPEM_CPU_STOP(SMatrix=SMatrix, y=y, Omega=self.potentialFunction, numIterations=self.numIterations, beta=self.beta, delta=self.delta, gamma=self.gamma, sigma=self.sigma, isSavingEachIteration=self.isSavingEachIteration, withTumor=withTumor)
238
- except Exception as e:
239
- warnings.warn(f"An error occurred in CPU implementation: {e}")
240
- result = None
241
-
242
- return result
243
-
244
- def _MAPEM(self, SMatrix, y, withTumor):
245
- """
246
- This method implements the MAPEM algorithm using either CPU or single-GPU PyTorch acceleration.
247
- Multi-GPU and Multi-CPU modes are not implemented for this algorithm.
248
- """
249
- result = None
250
- required_memory = calculate_memory_requirement(SMatrix, y)
251
-
252
- if self.isGPU:
253
- if check_gpu_memory(config.select_best_gpu(), required_memory):
254
- try:
255
- result = MAPEM._MAPEM_GPU(SMatrix=SMatrix, y=y, Omega=self.potentialFunction, numIterations=self.numIterations, beta=self.beta, delta=self.delta, gamma=self.gamma, sigma=self.sigma, isSavingEachIteration=self.isSavingEachIteration, withTumor=withTumor)
256
- except Exception as e:
257
- warnings.warn(f"Falling back to CPU implementation due to an error in GPU implementation: {e}")
258
- else:
259
- warnings.warn("Insufficient GPU memory for single GPU MAPEM. Falling back to CPU.")
260
-
261
- if result is None:
262
- try:
263
- result = MAPEM._MAPEM_CPU(SMatrix=SMatrix, y=y, Omega=self.potentialFunction, numIterations=self.numIterations, beta=self.beta, delta=self.delta, gamma=self.gamma, sigma=self.sigma, isSavingEachIteration=self.isSavingEachIteration, withTumor=withTumor)
264
- except Exception as e:
265
- warnings.warn(f"An error occurred in CPU implementation: {e}")
266
- result = None
267
-
268
- return result
269
-
270
- def _DEPIERRO(self, SMatrix, y, withTumor):
271
- """
272
- This method implements the DEPIERRO algorithm using either CPU or single-GPU PyTorch acceleration.
273
- Multi-GPU and Multi-CPU modes are not implemented for this algorithm.
274
- """
275
- result = None
276
- required_memory = calculate_memory_requirement(SMatrix, y)
277
-
278
- if self.isGPU:
279
- if check_gpu_memory(config.select_best_gpu(), required_memory):
280
- try:
281
- result = DEPIERRO._DEPIERRO_GPU(SMatrix=SMatrix, y=y, Omega=self.potentialFunction, numIterations=self.numIterations, beta=self.beta, sigma=self.sigma, isSavingEachIteration=self.isSavingEachIteration, withTumor=withTumor)
282
- except Exception as e:
283
- warnings.warn(f"Falling back to CPU implementation due to an error in GPU implementation: {e}")
284
- else:
285
- warnings.warn("Insufficient GPU memory for single GPU DEPIERRO. Falling back to CPU.")
286
-
287
- if result is None:
288
- try:
289
- result = DEPIERRO._DEPIERRO_CPU(SMatrix=SMatrix, y=y, Omega=self.potentialFunction, numIterations=self.numIterations, beta=self.beta, sigma=self.sigma, isSavingEachIteration=self.isSavingEachIteration, withTumor=withTumor)
290
- except Exception as e:
291
- warnings.warn(f"An error occurred in CPU implementation: {e}")
292
- result = None
293
-
294
- return result
295
-
230
+ raise ValueError(f"Unknown optimizer type: {self.optimizer.value}")