Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
df8d44d
NEW: Flow operator for CuPy
carterbox Jul 13, 2020
e3a479c
Merge branch 'flow' into cuda-lam
carterbox Jul 14, 2020
7a26903
Merge branch 'flow'
carterbox Jul 14, 2020
632343c
BUG: Copy cupy.map_coordinates from future version
carterbox Jul 14, 2020
360059b
TST: Skip Farneback on GPU
carterbox Jul 14, 2020
d33efe5
DOC: Add CuPy License to thier code section
carterbox Jul 14, 2020
2dc9634
Merge branch 'flow'
carterbox Jul 14, 2020
7f54560
Merge branch 'cuda-lam'
carterbox Jul 14, 2020
bf9bf79
REF: Use 'original' and 'unaligned' variable names
carterbox Jul 14, 2020
f29af01
NEW: Add solver for recovering distorted image
carterbox Jul 15, 2020
3ee2424
BUG: Lamino angles must by converted to CuPy arrays
carterbox Jul 15, 2020
2b51915
API: Use average of complex and real farneback results
carterbox Jul 20, 2020
0b81680
API: Add normalization to align solver using rho
carterbox Jul 20, 2020
bb9a69d
REF: Use Lanzcos remapping instead of scipy.map_coordinates
carterbox Jul 17, 2020
687d74b
Merge branch 'flow'
carterbox Jul 20, 2020
11698a6
NEW: Use CachedFFT for Laminography operator
carterbox Jul 22, 2020
a7014c2
BUG: Rescale farneback input by unaligned instead of original
carterbox Jul 22, 2020
7bb86bc
REF: Lamino scatter gather kernel for any dimensions
carterbox Jul 22, 2020
adea3bb
NEW: Lamino alignment problem in admm module
carterbox Jul 22, 2020
441ecb6
DEV: Save intermediate ADMM results and allow precomputing scales
carterbox Aug 7, 2020
e402185
Merge remote-tracking branch 'upstream/master' into catalyst
carterbox Aug 27, 2020
8076349
NEW: Allow specifying specific GPUs for ThreadPool
carterbox Aug 27, 2020
9409e29
BUG: Wrong indexing in CUDA kernel
carterbox Aug 24, 2020
87d8e60
STUB: Change how lamino-alignment intermediates are saved
carterbox Aug 27, 2020
3302397
Merge branch 'catalyst' of github.com:carterbox/tike into catalyst
carterbox Sep 1, 2020
e44c82c
STUB: ptycho-lamino-alignment
carterbox Sep 2, 2020
a110648
Merge remote-tracking branch 'upstream/master' into catalyst
carterbox Sep 2, 2020
d1d1247
Merge branch 'catalyst' of github.com:carterbox/tike into catalyst
carterbox Sep 2, 2020
0ddad30
ADMM that runs, but does it work?
carterbox Sep 8, 2020
2059b83
Loop through crop and rotate
carterbox Sep 8, 2020
e2a5f84
ADMM working but diverges
carterbox Sep 9, 2020
a78e6e8
API: better constants for rotation
carterbox Sep 10, 2020
e76dfd2
REF: Move lamino cost functions
carterbox Sep 10, 2020
588573b
Two problems only (remove alignment)
carterbox Sep 10, 2020
5b3c4d5
BUG: Change edge behavior to nearest for flow operator
carterbox Sep 16, 2020
bfeca3e
NEW: Implement correct adjoint Flow operator
carterbox Sep 19, 2020
ba7c4ee
REF: Autoselect operator in align.reconstruct()
carterbox Sep 21, 2020
360aa09
admm ptycho-align-lamino with penalty updates
carterbox Sep 22, 2020
2b5cc5d
TST: Add normalization test to operators tests
carterbox Sep 22, 2020
afb75d4
Required regularization arguments.
carterbox Sep 23, 2020
268bf60
Merge branch 'sequential' of github.com:carterbox/tike into sequential
carterbox Sep 23, 2020
db39039
NEW: Allow setting lamino accuracy from reconstruct
carterbox Sep 23, 2020
034fa2e
NEW: Add gaussian kernel to interp.cu
carterbox Sep 23, 2020
37674b5
NEW: Alignment operator composed of rotate and pad
carterbox Sep 25, 2020
d0c3c77
NEW: Only recale ptycho when flux is off by more than 1 percent
carterbox Sep 25, 2020
963d9e0
DEV: Before pad rotate as official operator
carterbox Sep 25, 2020
8fe33eb
MAI: Add tiff files to gitignore
carterbox Sep 29, 2020
2f7c26e
REF: Update Pad operator to pad symmetrically by default
carterbox Sep 29, 2020
f87bc40
API: Remove padding from Shift operator
carterbox Oct 2, 2020
707fb8a
NEW: Make some operators identity when params are None
carterbox Oct 2, 2020
a63e63f
BUG: Push lamino params to GPU
carterbox Oct 2, 2020
35d7c3a
PATCH: Make some operators identity
carterbox Oct 2, 2020
2c6d3d4
API: Have farneback solver return 'flow'
carterbox Oct 2, 2020
5932176
STY: Whitespace
carterbox Oct 2, 2020
5fdadbb
API: Use Alignment operator in alignment module
carterbox Oct 2, 2020
2eae5dd
DEV: Add helpful info to assert statement
carterbox Oct 7, 2020
3d9259a
API: Replace kwargs with catch for num_iter
carterbox Oct 7, 2020
7e2ff9e
API: Switch from 'wrap' to 'constant value' interpolation
carterbox Oct 7, 2020
89dfb73
BUG: cval was always set to zero in rotate
carterbox Oct 8, 2020
4de3ce2
DEV: Avoid atomicAdd() in interpolation kernel
carterbox Oct 8, 2020
86dc204
REF: Split admm into module
carterbox Oct 9, 2020
a4d8258
Merge branch 'flow-adjoint' into sequential
carterbox Oct 23, 2020
f250d4a
Merge branch 'master' into catalyst
carterbox Jan 28, 2021
123db2a
BUG: Use float32 for Farneback API
carterbox Feb 4, 2021
1f14888
NEW: Add Shift operator to Alignment composition
carterbox Feb 4, 2021
8ed0770
Merge branch 'parallel-lamino' into catalyst
carterbox Feb 5, 2021
e643da2
API: Make laminography theta a parameter instead of constant
carterbox Feb 6, 2021
e123336
NEW: Add regularizer to cross_correlation
carterbox Feb 8, 2021
cbfe16f
REF: Modularize admm subproblems into separate functions
carterbox Feb 10, 2021
138f81c
BUG: Missing import in tike.admm.alignment
carterbox Feb 11, 2021
c478b3c
REF: Save result before reconstruction admm.lamino
carterbox Feb 11, 2021
09fd5e6
NEW: Add inverse operator to alignment module
carterbox Feb 11, 2021
02e5d47
NEW: Save ptycho result in admm.ptycho
carterbox Feb 11, 2021
cab952f
NEW: Add rescale optional parameter to ptycho
carterbox Feb 11, 2021
494131f
BUG: inverse alignment operator
carterbox Feb 11, 2021
f56724b
NEW: Smaller cross correlation weight
carterbox Feb 11, 2021
7c0ce98
NEW: Set subproblem iters separate from cg_iter
carterbox Feb 11, 2021
551724b
BUG: Proper alignment in ptycho_lamino
carterbox Feb 11, 2021
f6ccac9
Merge remote-tracking branch 'upstream/master' into catalyst
carterbox Feb 11, 2021
2557b2a
REF: Use same subproblems for each formulation
carterbox Feb 11, 2021
6a4bbbc
BUG: Mismatched indent
carterbox Feb 12, 2021
7aad5e7
BUG: Changed parameter name
carterbox Feb 12, 2021
66e966c
BUG: Missing imports
carterbox Feb 12, 2021
6f10f32
STY: Name all parameters
carterbox Feb 12, 2021
cbeccce
REF: Use MSE instead of L2-Norm in Lagrangian
carterbox Feb 12, 2021
9157249
DOC: Save angle instead of imag in lamino subproblem
carterbox Feb 12, 2021
b4c6c08
Merge remote-tracking branch 'origin/rescale-lamino' into catalyst
carterbox Feb 16, 2021
89c382b
NEW: Access early termination for ptycho subproblem
carterbox Feb 16, 2021
a3b7340
REF: Remove skimage dependency for center mass
carterbox Feb 16, 2021
b2fbc47
REF: Ensure correct lagrangians again
carterbox Feb 16, 2021
64eb859
REF: Update penalty params more often
carterbox Feb 16, 2021
93e2146
BUG: Reenable u broadcase
carterbox Feb 16, 2021
39d6571
NEW: Enable center of mass in alignment subproblem
carterbox Feb 16, 2021
2fd446d
REF: Only minmax when needed
carterbox Feb 16, 2021
d5b88b3
REF: Put admm subproblem into own module
carterbox Feb 16, 2021
6444f19
BUG: Don't convert scalars to arrays
carterbox Feb 23, 2021
190fecd
NEW: Remove duplicate interpolation in Alignment operator
carterbox Feb 23, 2021
2f3b1b2
BUG: Start with shift as initial flow
carterbox Feb 25, 2021
a3e9980
DOC: Fix typo in penalty docstring
carterbox Feb 25, 2021
7f46b38
API: Change regularization scheme for cross_correlation
carterbox Feb 25, 2021
84229a4
BUG: Properly log strings in log_line
carterbox Feb 25, 2021
9b6660a
NEW: Track winsize parameter
carterbox Feb 25, 2021
b4a7256
BUG: Avoid MPI buffer overflow
carterbox Mar 9, 2021
49b0ebf
API: Use overwrite intermediate saves
carterbox Mar 9, 2021
1c925d6
REF: Move alignment operator to left
carterbox Mar 12, 2021
177940c
REF: Solve inverse flow problem
carterbox Mar 15, 2021
e01cd8d
NEW: Gradient operator for reg subproblem
carterbox Mar 16, 2021
95d02d4
NEW: Gradient operator for reg subproblem
carterbox Mar 16, 2021
7779068
REF: Move laminography cost/grad out of operators
carterbox Mar 19, 2021
fe4d35c
NEW: Add functions for total variation regularization
carterbox Mar 19, 2021
9567f19
NEW: Add regularization to lamino cost function
carterbox Mar 22, 2021
3425b3a
Merge branch 'total-variation' into catalyst
carterbox Mar 22, 2021
b1d725c
NEW: Change tomography linear approximation
carterbox Mar 23, 2021
e991225
BUG: New handling of K
carterbox Mar 23, 2021
7a3178b
STUB: Regularization subproblem
carterbox Mar 24, 2021
064e4c2
REF: Avoid astype() copies
carterbox Mar 26, 2021
bf1c8f9
REF: Reduce Lamino mem footprint
carterbox Mar 27, 2021
5b9f5c6
Merge remote-tracking branch 'origin/catalyst' into catalyst
carterbox Mar 29, 2021
7e17193
Undo new tomography model
carterbox Mar 30, 2021
cf1bfc5
BUG: Fix lamino step length search
carterbox Mar 30, 2021
b31fda1
BUG: Add missing equals sign
carterbox Mar 30, 2021
4247102
DOC: Add more information to Lamino docstrings
carterbox Jul 21, 2021
b099b32
Merge branch 'master' into catalyst
carterbox Jul 21, 2021
f077d96
DOC: Use object instead of particle label
carterbox Jul 23, 2021
ec201f9
REF: Allow skipping ptycho subproblem in alignment lamino admm
carterbox Jul 23, 2021
9acb11b
BUG: Add error if padded shape is smaller than unpadded
carterbox Jul 27, 2021
69ca52f
DEV: Require 2x upsampling for lamino problem to mitigate noise
carterbox Jul 27, 2021
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,7 @@ core
.DS_Store
.nfs*

*.tiff

# MPI host files
host_list
33 changes: 0 additions & 33 deletions src/broken/reg.py

This file was deleted.

4 changes: 4 additions & 0 deletions src/tike/admm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .admm import *
from .al import *
from .pal import *
from .pl import *
69 changes: 69 additions & 0 deletions src/tike/admm/admm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import logging

import numpy as np

import tike.align
import tike.lamino
import tike.ptycho


def simulate(
u,
scan,
probe,
flow,
angle,
tilt,
theta,
padded_shape,
detector_shape,
):
phi = np.exp(1j * tike.lamino.simulate(
obj=u,
tilt=tilt,
theta=theta,
))
psi = tike.align.simulate(
original=phi,
flow=flow,
padded_shape=padded_shape,
angle=angle,
cval=1.0,
)
data = tike.ptycho.simulate(
psi=psi,
probe=probe,
detector_shape=detector_shape,
scan=scan,
)
return data, psi, phi


def print_log_line(**kwargs):
"""Print keyword arguments and values on a single comma-separated line.

The format of the line is as follows:

```
foo: 003, bar: +1.234e+02, hello: world\n
```

Parameters
----------
line: dictionary
The key value pairs to be printed.

"""
line = []
for k, v in kwargs.items():
# Use special formatting for float and integers
if isinstance(v, (float, np.floating)):
line.append(f'"{k}": {v:6.3e}')
elif isinstance(v, (int, np.integer)):
line.append(f'"{k}": {v:3d}')
elif isinstance(v, str):
line.append(f'"{k}": "{v}"')
else:
line.append(f'"{k}": {v}')
# Combine all the strings and strip the last comma
print("{", ", ".join(line), "}", flush=True)
156 changes: 156 additions & 0 deletions src/tike/admm/al.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import logging

import numpy as np
import cupy as cp

import tike.admm.subproblem
import tike.communicator

from .admm import print_log_line

logger = logging.getLogger(__name__)


def ptycho__align_lamino(
data,
psi,
scan,
probe,
theta,
tilt,
angle,
w,
flow=None,
shift=None,
niter=1,
interval=8,
folder=None,
cg_iter=4,
align_method=False,
skip_ptycho=False,
):
"""Solve the joint ptycho-lamino problem using ADMM."""
presult = {
'psi': psi,
'scan': scan,
'probe': probe,
}

u = np.zeros((w, w, w), dtype='complex64')
Hu = np.ones((len(theta), w, w), dtype='complex64')
phi = Hu
Aφ = np.ones(psi.shape, dtype='complex64')

λ_l = np.zeros([len(theta), w, w], dtype='complex64')
ρ_l = 0.5

comm = tike.communicator.MPICommunicator()

with cp.cuda.Device(comm.rank if comm.size > 1 else None):

if not skip_ptycho:
presult, _ = tike.admm.subproblem.ptycho(
# constants
comm=comm,
data=data,
λ=None,
ρ=None,
Aφ=None,
# updated
presult=presult,
# parameters
num_iter=4 * niter,
cg_iter=cg_iter,
folder=folder,
save_result=niter + 1,
rescale=True,
rtol=1e-6,
)

for k in range(1, niter + 1):
logger.info(f"Start ADMM iteration {k}.")
save_result = k if k % interval == 0 else False

(
phi,
_,
_,
flow,
shift,
Aφ,
align_cost,
winsize,
) = tike.admm.subproblem.align(
# constants
comm=comm,
psi=presult['psi'],
angle=angle,
Hu=Hu,
λ_l=λ_l,
ρ_l=ρ_l,
# updated
phi=phi,
λ_p=None,
ρ_p=1,
flow=flow,
shift=shift,
Aφ0=None,
# parameters
align_method=align_method,
cg_iter=cg_iter,
num_iter=4,
folder=folder,
save_result=save_result,
winsize=winsize if k > 1 else 129,
)

(
u,
λ_l,
ρ_l,
Hu,
lamino_cost,
) = tike.admm.subproblem.lamino(
# constants
comm=comm,
phi=phi,
theta=theta,
tilt=tilt,
# updated
u=u,
λ_l=λ_l,
ρ_l=ρ_l,
Hu0=Hu,
# parameters
num_iter=4,
cg_iter=cg_iter,
folder=folder,
save_result=save_result,
)

# Record metrics for each subproblem
ψAφ = presult['psi'] - Aφ
φHu = phi - Hu
lagrangian = (
[np.mean(np.real(ψAφ.conj() * ψAφ))],
[
2 * np.mean(np.real(λ_l.conj() * φHu)) +
ρ_l * np.mean(np.real(φHu.conj() * φHu))
],
[align_cost],
)
lagrangian = [comm.gather(x) for x in lagrangian]

if comm.rank == 0:
lagrangian = [np.sum(x) for x in lagrangian]
print_log_line(
k=k,
ρ_l=ρ_l,
winsize=winsize,
align_method=align_method,
Lagrangian=np.sum(lagrangian[:2]),
ψAφ=lagrangian[0],
φHu=lagrangian[1],
align=lagrangian[2],
lamino=float(lamino_cost),
)
Loading