diff --git a/.gitignore b/.gitignore index 7b81e4b..0ff82bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .gitignore +.ipynb_checkpoints/ *~ \#*# .#* diff --git a/CMakeLists.txt b/CMakeLists.txt index 3747208..3c3ba38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}) diff --git a/cmake/cmake_settings_maxwell.txt b/cmake/cmake_settings_maxwell.txt new file mode 100644 index 0000000..53dc1b0 --- /dev/null +++ b/cmake/cmake_settings_maxwell.txt @@ -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 diff --git a/examples/simple.ipynb b/examples/simple.ipynb index b918379..908ca94 100644 --- a/examples/simple.ipynb +++ b/examples/simple.ipynb @@ -4,7 +4,10 @@ "cell_type": "code", "execution_count": 9, "metadata": { - "collapsed": true + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } }, "outputs": [], "source": [ @@ -21,7 +24,10 @@ "cell_type": "code", "execution_count": 16, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -36,7 +42,10 @@ "cell_type": "code", "execution_count": 28, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -833,7 +842,10 @@ "cell_type": "code", "execution_count": 46, "metadata": { - "collapsed": true + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } }, "outputs": [], "source": [ @@ -849,7 +861,10 @@ "cell_type": "code", "execution_count": 47, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -870,7 +885,10 @@ "cell_type": "code", "execution_count": 49, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -886,7 +904,10 @@ "cell_type": "code", "execution_count": 54, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -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 } diff --git a/src/_spimage_reconstructor.py b/src/_spimage_reconstructor.py index f9401d0..a0454e0 100644 --- a/src/_spimage_reconstructor.py +++ b/src/_spimage_reconstructor.py @@ -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() @@ -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) @@ -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: @@ -597,9 +613,15 @@ 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: @@ -607,8 +629,13 @@ def reconstruct(self): 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, @@ -649,9 +676,15 @@ 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: @@ -659,8 +692,13 @@ def reconstruct(self): 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, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9e01479..fd746eb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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)