Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gitignore
.ipynb_checkpoints/
*~
\#*#
.#*
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW) # CMake 3.0
endif()

# If the variable is empty, set a sensible default (e.g., native or a common architecture)
## PA: Fix for maxwell
#if(NOT CMAKE_CUDA_ARCHITECTURES)
#set(CMAKE_CUDA_ARCHITECTURES native)
#endif()

project(spimage)

include(CTest)
Expand Down Expand Up @@ -163,6 +169,10 @@ endif()

list(APPEND TESTS_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES} ${GSL_LIBRARIES})
list(APPEND SPIMAGE_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES})

## PA: Fix for maxwell
#find_library(MATH_LIBRARY m)
#list(APPEND SPIMAGE_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES} ${MATH_LIBRARY})

if(LINK_TO_DMALLOC)
list(APPEND SPIMAGE_LIBRARIES ${DMALLOC_LIBRARY})
Expand Down
29 changes: 29 additions & 0 deletions cmake/cmake_settings_maxwell.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- options for ccmake that i used for building on maxwell
-- I also had to add the m library in libspimage/CMakeLists.txt and libspimage/test/CMakeLists.txt
-- On maxwell, i used python 3.9 with venv, and loaded the modules mpi/openmpi-x86_64, maxwell, and cuda
-- -PA
--
--
--
-- CUDA found. Using CUDA.
-- Configuring done (1.5s)
-- Generating done (0.1s)
-- Build files have been written to: /gpfs/exfel/u/usr/SPB/202501/p006933/Shared/dfly-p6933/libspimage/build
-- Cache values
BUILD_STATIC_LIB:BOOL=
BUILD_TESTING:BOOL=ON
CMAKE_BUILD_TYPE:STRING=
CMAKE_CUDA_ARCHITECTURES:STRING=
-- venv directory VVV
CMAKE_INSTALL_PREFIX:PATH=/home/patricka/p6933/usr/Shared/dfly-p6933/dfly
CUDAToolkit_BIN_DIR:PATH=/software/cuda/cuda-12.6/bin
CUDAToolkit_CUPTI_INCLUDE_DIR:PATH=/software/cuda/cuda-12.6/include
DMALLOC_USE:BOOL=OFF
DOUBLE_PRECISION:BOOL=OFF
HDF5_C_LIBRARY_hdf5:FILEPATH=/usr/lib64/openmpi/lib/libhdf5.so
INCLUDE_DEPENDENCIES:BOOL=
-- venv directory VVV
PYTHON_EXECUTABLE:PATH=/home/patricka/p6933/usr/Shared/dfly-p6933/dfly/bin/python3.9
PYTHON_WRAPPERS:BOOL=ON
SP_MEM_DEBUG:BOOL=OFF
USE_CUDA:BOOL=ON
47 changes: 34 additions & 13 deletions examples/simple.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": [
Expand All @@ -21,7 +24,10 @@
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -36,7 +42,10 @@
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand Down Expand Up @@ -833,7 +842,10 @@
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": true
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": [
Expand All @@ -849,7 +861,10 @@
"cell_type": "code",
"execution_count": 47,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -870,7 +885,10 @@
"cell_type": "code",
"execution_count": 49,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand All @@ -886,7 +904,10 @@
"cell_type": "code",
"execution_count": 54,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand Down Expand Up @@ -1681,23 +1702,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
40 changes: 39 additions & 1 deletion src/_spimage_reconstructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,16 @@ def _prepare_reconstruction(self):
if self._i_phasing_algorithms != self._number_of_iterations:
self._log("Connot prepare reconstruction. Phasing algorithms initialised are not in line with the set number of iterations.","ERROR")
self._ready = False

if self._number_of_outputs_images <0:
self._number_of_outputs_images = self._number_of_iterations
if self._number_of_outputs_scores <0:
self._number_of_outputs_scores = self._number_of_iterations

if not self._ready:
return


self._init_amplitudes()
self._init_initial_support()
self._init_iterations()
Expand Down Expand Up @@ -540,8 +548,10 @@ def _init_phaser(self):
self._sp_phaser = spimage.sp_phaser_alloc()
if self._use_gpu:
pe = spimage.SpEngineCUDA
self._log(f"Set phasing engine to GPU.")
else:
pe = spimage.SpEngineCPU
self._log(f"Set phasing engine to CPU.")
self._log("Initialising phaser with the phasing algorithm %s and the support algorithm %s." % (self._phasing_algorithms[0]["type"],self._support_algorithms[0]["type"]))
spimage.sp_phaser_init(self._sp_phaser, self._phasing_algorithms[0]["spimage_phasing"], self._support_algorithms[0]["spimage_support_array"], pe)
spimage.sp_phaser_set_amplitudes(self._sp_phaser, self._sp_amplitudes)
Expand All @@ -550,9 +560,15 @@ def _init_phaser(self):
self._phaser_dirty = False
self._log("Phaser initialized.","DEBUG")

def reconstruct(self):
def reconstruct(self, on_output=None):
"""
Performs a single reconstruction with the specified configuration and outputs a dictionary with the results.

If \"on_output\" is given, it must be a callable accepting the keyword arguments
(iteration, images, scores). It is called every time images and/or scores are
written to the output, with \"images\" and/or \"scores\" set to None if not written
at that iteration. This can be used e.g. to save output incrementally (per step)
to disk instead of only after the full reconstruction has finished.
"""
self._prepare_reconstruction()
if not self._ready:
Expand Down Expand Up @@ -597,18 +613,29 @@ def reconstruct(self):
iteration0_sup = self._iteration
self._sp_phaser.sup_algorithm = self._support_algorithms[i_sup]["spimage_support_array"]
self._log("Change of support algorithm to %s." % self._support_algorithms[i_sup]["type"],"INFO")
out_images = None
out_scores = None
if self._iteration in self._out_iterations_images:
[real_space[i_out_images,:,:],support[i_out_images,:,:]] = self._get_curr_model(shifted=False)
[fourier_space[i_out_images,:,:],mask[i_out_images,:,:]] = self._get_curr_fmodel(shifted=False)
out_images = {"real_space":real_space[i_out_images],
"support":support[i_out_images],
"fourier_space":fourier_space[i_out_images],
"mask":mask[i_out_images]}
i_out_images += 1
self._log("Outputting images.","DEBUG")
if self._iteration in self._out_iterations_scores:
scores = self._get_scores()
fourier_error[i_out_scores] = scores["fourier_error"]
real_error[i_out_scores] = scores["real_error"]
support_size[i_out_scores] = scores["support_size"]
out_scores = {"real_error":real_error[i_out_scores],
"fourier_error":fourier_error[i_out_scores],
"support_size":support_size[i_out_scores]}
i_out_scores += 1
self._log("Outputting scores.","DEBUG")
if on_output is not None and (out_images is not None or out_scores is not None):
on_output(iteration=self._iteration, images=out_images, scores=out_scores)
self._iteration = None
out = {"iteration_index_images":self._out_iterations_images,
"iteration_index_scores":self._out_iterations_scores,
Expand Down Expand Up @@ -649,18 +676,29 @@ def reconstruct(self):
iteration0_sup = self._iteration
self._sp_phaser.sup_algorithm = self._support_algorithms[i_sup]["spimage_support_array"]
self._log("Change of support algorithm to %s." % self._support_algorithms[i_sup]["type"],"INFO")
out_images = None
out_scores = None
if self._iteration in self._out_iterations_images:
[real_space[i_out_images,:,:,:],support[i_out_images,:,:,:]] = self._get_curr_model(shifted=False)
[fourier_space[i_out_images,:,:,:],mask[i_out_images,:,:,:]] = self._get_curr_fmodel(shifted=False)
out_images = {"real_space":real_space[i_out_images],
"support":support[i_out_images],
"fourier_space":fourier_space[i_out_images],
"mask":mask[i_out_images]}
i_out_images += 1
self._log("Outputting images.","DEBUG")
if self._iteration in self._out_iterations_scores:
scores = self._get_scores()
fourier_error[i_out_scores] = scores["fourier_error"]
real_error[i_out_scores] = scores["real_error"]
support_size[i_out_scores] = scores["support_size"]
out_scores = {"real_error":real_error[i_out_scores],
"fourier_error":fourier_error[i_out_scores],
"support_size":support_size[i_out_scores]}
i_out_scores += 1
self._log("Outputting scores.","DEBUG")
if on_output is not None and (out_images is not None or out_scores is not None):
on_output(iteration=self._iteration, images=out_images, scores=out_scores)
self._iteration = None
out = {"iteration_index_images":self._out_iterations_images,
"iteration_index_scores":self._out_iterations_scores,
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ if(CUDA_FOUND)
#set_target_properties(tests PROPERTIES CUDA_ARCHITECTURES "35")
endif()


target_link_libraries(tests PRIVATE ${TESTS_LIBRARIES})

## PA: Fix for maxwell
#find_library(MATH_LIBRARY m)
#target_link_libraries(tests PRIVATE ${TESTS_LIBRARIES} MATH_LIBRARY)

enable_testing()

add_test(linearAlgebra tests -l)
Expand Down
Loading