Skip to content

Commit

Permalink
Merge pull request #1 from slimgroup/testing
Browse files Browse the repository at this point in the history
re-enable most test
  • Loading branch information
mloubout authored Aug 24, 2020
2 parents 7fa2e62 + 917145f commit 04176ab
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 144 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/cancel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Cancel

on: [push]

jobs:
cancel:
name: 'Cancel Previous Runs'
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: styfle/[email protected]
with:
# Ids to cancel op/judi
# https://api.github.com/repos/slimgroup/JUDI.jl/actions/workflows
workflow_id: 2306091
access_token: ${{ github.token }}
54 changes: 54 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI-SetIntersectionProjection

on:
# Trigger the workflow on push to master or pull request
# to be merged in master
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
version: ['1.1', '1.2', '1.3', '1.4', '1.5', 'nightly']
os: [ubuntu-latest]

include:
- version: 1.3
os: macos-latest

- version: 1.4
os: macos-latest

steps:
- name: Checkout SetIntersectionProjection
uses: actions/checkout@v2

- name: Setup julia
uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: x64

- name: Add SLIM registery
run: |
julia --color=yes --check-bounds=yes -e 'using Pkg;Pkg.update();Pkg.Registry.add(RegistrySpec(url="https://github.com/slimgroup/SLIMregistryJL.git"))'
- name: Build SetIntersectionProjection
uses: julia-actions/julia-buildpkg@latest

- name: Run tests
uses: julia-actions/julia-runtest@latest

- uses: julia-actions/julia-uploadcodecov@latest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
15 changes: 7 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@

name = "SetIntersectionProjection"
uuid = "335f7d24-6316-57dd-9c3a-df470f2b739e"
authors = ["Bas Peters <[email protected]>"]
version = "0.0.0"
version = "0.1.0"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
DistributedArrays = "aaf54ef3-cdf8-58ed-94cc-d582ad619b94"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JOLI = "bb331ad6-a1cf-11e9-23da-9bcb53c69f6f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SortingAlgorithms = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
JOLI = "bb331ad6-a1cf-11e9-23da-9bcb53c69f6f"
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"
SortingAlgorithms = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
DistributedArrays = "aaf54ef3-cdf8-58ed-94cc-d582ad619b94"
2 changes: 1 addition & 1 deletion src/cg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export cg

function cg(A::SparseMatrixCSC{T1,Int},b::Array{T2,1}; kwargs...) where {T1,T2}
x = zeros(promote_type(T1,T2),size(A,2)) # pre-allocate
return cg(v -> At_mul_B!(1.0,A,v,0.0,x),b;kwargs...) # multiply with transpose of A for efficiency
return cg(v -> mul!(x, transpose(A), v, 1.0, 0.0),b; kwargs...) # multiply with transpose of A for efficiency
end

cg(A,b::Vector;kwargs...) = cg(x -> A*x,b;kwargs...)
Expand Down
51 changes: 25 additions & 26 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end
@assert nprocs() > 3
@assert nworkers() >= 3

@everywhere using DistributedArrays
@everywhere using DistributedArrays, SparseArrays
@everywhere using JOLI

@everywhere using SetIntersectionProjection
Expand All @@ -23,32 +23,31 @@ end
end



@testset "SetIntersectionProjection" begin

include("test_projectors.jl")
include("test_setup_constraints.jl")

#still need to port the stuff below to Julia 1.1

# include("test_TD_OPs.jl")
# include("test_prox_l2s!.jl")
# include("test_argmin_x.jl")
# include("test_update_y_l.jl")
#
# #parallel scripts
# include("test_update_y_l_parallel.jl")
# include("test_adapt_rho_gamma_parallel.jl")
#
# #linear algebra subroutines
# include("test_cg.jl")
# include("test_CDS_Mvp.jl")
# include("test_CDS_scaled_add.jl")
# include("test_Q_update.jl")
#
# #test full algorithms
# include("test_PARSDMM.jl")
# include("test_PARSDMM_parallel.jl")
# include("test_PARSDMM_multilevel.jl")
include("test_projectors.jl")
include("test_setup_constraints.jl")

#still need to port the stuff below to Julia 1.1

include("test_TD_OPs.jl")
include("test_prox_l2s!.jl")
include("test_argmin_x.jl")
include("test_update_y_l.jl")

#parallel scripts
include("test_update_y_l_parallel.jl")
include("test_adapt_rho_gamma_parallel.jl")

#linear algebra subroutines
include("test_cg.jl")
include("test_CDS_Mvp.jl")
include("test_CDS_scaled_add.jl")
include("test_Q_update.jl")

#test full algorithms
# include("test_PARSDMM.jl")
# include("test_PARSDMM_parallel.jl")
# include("test_PARSDMM_multilevel.jl")

end
19 changes: 9 additions & 10 deletions test/test_PARSDMM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ options=PARSDMM_options()
options.FL = Float64
options.parallel = false
options.zero_ini_guess = true
options.linear_inv_prob_flag = false

x=randn(100,201)

comp_grid=compgrid((1.0, 1.0),(100, 201))
comp_grid = compgrid((1.0, 1.0),(100, 201))
x = vec(x)
m2 = deepcopy(x)
x_ini2 = deepcopy(x)
Expand All @@ -18,8 +17,8 @@ constraint= Dict()
#check if input returns if the input satisfies the constraints
#bound constraints
constraint["use_bounds"]=true
constraint["m_min"]=minimum(vec(x))
constraint["m_max"]=maximum(vec(x))
constraint["min"]=minimum(vec(x))
constraint["max"]=maximum(vec(x))

(P_sub,TD_OP,TD_Prop) = setup_constraints(constraint,comp_grid,options.FL)
(TD_OP,AtA,l,y) = PARSDMM_precompute_distribute(TD_OP,TD_Prop,comp_grid,options)
Expand All @@ -33,8 +32,8 @@ constraint= Dict()
#add a few convex constraints. The projected model should satisfy these constraints
#bound constraints
constraint["use_bounds"]=true
constraint["m_min"]=0.5*minimum(vec(x))
constraint["m_max"]=0.5*maximum(vec(x))
constraint["min"]=0.5*minimum(vec(x))
constraint["max"]=0.5*maximum(vec(x))

#transform domain bounds
(TD_OP, AtA_diag, dense, TD_n)=get_TD_operator(comp_grid,"D_z",options.FL)
Expand Down Expand Up @@ -182,8 +181,8 @@ constraint= Dict()
#add a few convex constraints which the model already satisfies
#bound constraints
constraint["use_bounds"]=false
constraint["m_min"]=1.0*minimum(vec(c_l_solution))
constraint["m_max"]=1.456*maximum(vec(c_l_solution))
constraint["min"]=1.0*minimum(vec(c_l_solution))
constraint["max"]=1.456*maximum(vec(c_l_solution))

#transform domain bounds
(TD_OP, AtA_diag, dense, TD_n)=get_TD_operator(comp_grid,"D_z",options.FL)
Expand Down Expand Up @@ -236,8 +235,8 @@ constraint["TD_nuclear_operator_1"]="identity"
#add a few convex constraints which the model already satisfies
#bound constraints
constraint["use_bounds"]=true
constraint["m_min"]=1.0*minimum(x)
constraint["m_max"]=0.50*maximum(x)
constraint["min"]=1.0*minimum(x)
constraint["max"]=0.50*maximum(x)

#transform domain bounds
(TD_OP, AtA_diag, dense, TD_n)=get_TD_operator(comp_grid,"D_z",options.FL)
Expand Down
14 changes: 9 additions & 5 deletions test/test_Q_update.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#sparse matrix
A=sprandn(100,100,0.1)
B=Vector{SparseMatrixCSC{Float64,Int64}}(2)
B=Vector{SparseMatrixCSC{Float64,Int64}}(undef, 2)
B[1]=sprandn(100,100,0.1)
B[2]=sprandn(100,100,0.1)
#make sure all nonzero diagonals in B are also in A, otherwise CDS doesnt work
Expand All @@ -14,15 +14,15 @@
maxit=100;
p=2
log_PARSDMM = log_type_PARSDMM(zeros(maxit,p-1),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit),zeros(maxit,p),zeros(maxit,p),zeros(maxit),zeros(maxit),0.00,0.00,0.00,0.00,0.00,0.00,0.00);
rho=Vector{Float64}(2)
rho=Vector{Float64}(undef, 2)
rho[1]=1.0
rho[2]=1.0
log_PARSDMM.rho[1,1]=2.0
log_PARSDMM.rho[1,2]=3.0

#add A = A+ 1.0*B[1] + 2.0*B[2]
i=1
ind_updated = find(rho .!= log_PARSDMM.rho[i,:]) #::Vector{Integer}# locate changed rho index
ind_updated = findall(rho .!= log_PARSDMM.rho[i,:]) #::Vector{Integer}# locate changed rho index
ind_updated = convert(Array{Int64,1},ind_updated)
#use explicit solution:
if isempty(ind_updated) == false
Expand All @@ -33,7 +33,11 @@
#use Q_update:
TI=Int64
TF=Float64
TD_Prop=set_properties(zeros(99),zeros(99),zeros(99),Vector{Tuple{TI,TI}}(99),Vector{Tuple{String,String}}(99),zeros(99),Vector{Vector{TI}}(99))
TD_Prop=set_properties(zeros(Bool, 99), zeros(Bool, 99), zeros(Bool, 99),
fill!(Vector{Tuple{TI,TI}}(undef, 99), (0, 0)),
fill!(Vector{Tuple{String,String, String, String}}(undef, 99), ("", "", "", "")),
zeros(Bool, 99),
Vector{Vector{TI}}(undef,99))
A2=Q_update!(A2,B2,TD_Prop,rho,ind_updated,log_PARSDMM,i,[])

x=randn(size(A,2))
Expand All @@ -43,7 +47,7 @@
(R_A,offset_A)=mat2CDS(A3)
(R_B1,offset_B1)=mat2CDS(B[1])
(R_B2,offset_B2)=mat2CDS(B[2])
R_B=Vector{Array{Float64,2}}(2)
R_B=Vector{Array{Float64,2}}(undef, 2)
R_B[1]=R_B1
R_B[2]=R_B2
TD_Prop.AtA_offsets[1]=offset_B1
Expand Down
30 changes: 15 additions & 15 deletions test/test_TD_OPs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
D2z = get_discrete_Grad(n1,n2,h1,h2,"D_z")

x=zeros(n1,n2) #test on a 'cross' image
x[:,3]=1.0
x[4,:]=1.0
x[:,3].=1.0
x[4,:].=1.0

a1 = D2x*vec(x); a1=reshape(a1,n1-1,n2)
a2 = D2z*vec(x); a2=reshape(a2,n1,n2-1)
Expand All @@ -21,17 +21,17 @@
a3b = reshape(a3b,n1-1,n2)

#this test depends on the values of h1 and h2, as well as the type of derivative
@test a1==diff(x,1)./h1
@test a2==diff(x,2)./h2
@test a1==diff(x, dims=1)./h1
@test a2==diff(x, dims=2)./h2

#some more general tests:
@test countnz(a1[:,3])==0
@test count(!iszero, a1[:,3])==0
for i in [1 2 4 5 6]
@test a1[:,1]==a1[:,i]
end

#some more general tests:
@test countnz(a2[4,:])==0
@test count(!iszero, a2[4,:])==0
for i in [1 2 3 5 6 7 8 9]
@test a2[1,:]==a2[i,:]
end
Expand All @@ -52,32 +52,32 @@
D3z = get_discrete_Grad(n1,n2,n3,h1,h2,h3,"D_z")

x=zeros(n1,n2,n3) #test on a 'cross' image
x[2,:,:]=1.0
x[:,4,:]=1.0
x[:,:,3]=1.0
x[2,:,:].=1.0
x[:,4,:].=1.0
x[:,:,3].=1.0

a1 = D3x*vec(x); a1=reshape(a1,n1-1,n2,n3)
a2 = D3y*vec(x); a2=reshape(a2,n1,n2-1,n3)
a3 = D3z*vec(x); a3=reshape(a3,n1,n2,n3-1)
for i=1:n2
@test a1[:,i,:]==diff(x[:,i,:],1)./h1
@test a1[:,i,:]==diff(x[:,i,:], dims=1)./h1
end
for i=1:n3
@test a1[:,:,i]==diff(x[:,:,i],1)./h1
@test a1[:,:,i]==diff(x[:,:,i], dims=1)./h1
end

for i=1:n1
@test a2[i,:,:]==diff(x[i,:,:],1)./h2
@test a2[i,:,:]==diff(x[i,:,:], dims=1)./h2
end
for i=1:n3
@test a2[:,:,i]==diff(x[:,:,i],2)./h2
@test a2[:,:,i]==diff(x[:,:,i], dims=2)./h2
end

for i=1:n1
@test a3[i,:,:]==diff(x[i,:,:],2)./h3
@test a3[i,:,:]==diff(x[i,:,:], dims=2)./h3
end
for i=1:n2
@test a3[:,i,:]==diff(x[:,i,:],2)./h3
@test a3[:,i,:]==diff(x[:,i,:], dims=2)./h3
end

end
Loading

0 comments on commit 04176ab

Please sign in to comment.