Skip to content

Commit 3eb456d

Browse files
committed
start migration to cobrexa2
1 parent 8ab5549 commit 3eb456d

File tree

6 files changed

+49
-72
lines changed

6 files changed

+49
-72
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "CuFluxSampler"
22
uuid = "d04bc951-f907-4aa3-859a-fc6f9fe5eea9"
33
authors = ["Mirek Kratochvil <miroslav.kratochvil@uni.lu>"]
4-
version = "0.1.0"
4+
version = "0.2.0"
55

66
[deps]
77
COBREXA = "babc4406-5200-4a30-9033-bf5ae714c842"
@@ -11,8 +11,8 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1111
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1212

1313
[compat]
14-
COBREXA = "1"
15-
CUDA = "4"
14+
COBREXA = "2"
15+
CUDA = "5"
1616
DocStringExtensions = "0.9"
1717
julia = "1.6"
1818

src/CuFluxSampler.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ using DocStringExtensions
77
import COBREXA
88
import CUDA
99
import SparseArrays
10+
import StableRNGs: StableRNG
1011

11-
include("TeaRNG.jl")
12-
include("FullAffineHR.jl")
13-
include("AffineHR.jl")
14-
include("ACHR.jl")
12+
include("tea_rng.jl")
13+
include("full_affine_hr.jl")
14+
include("affine_hr.jl")
15+
include("achr.jl")
1516

1617
end # module CuFluxSampler

src/ACHR.jl renamed to src/achr.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
module ACHR
2-
using ..CUDA
3-
using ..DocStringExtensions
4-
using SparseArrays
5-
6-
import ..COBREXA
7-
import ..TeaRNG
8-
import Random
91

102
"""
113
$(TYPEDSIGNATURES)
124
135
A traditional artificially-centered hit-and-run algorithm that starts with
146
`start` points.
157
8+
To use this on a model, use [`flux_sample`](@ref) or
9+
[`sample_constraints`](@ref); most parameters are filled in correctly by these
10+
functions.
11+
1612
Refer to the documentation in module AffineHR for the meaning of arguments.
1713
"""
18-
function sample(
19-
m::COBREXA.MetabolicModel,
20-
start::AbstractMatrix;
21-
iters::Int,
22-
bound_stoichiometry::Bool = false,
23-
check_stoichiometry::Bool = true,
14+
function sample_chain_achr_cuda(
15+
sample_c::COBREXA.M;
16+
variable_lower_bounds::COBREXA.V,
17+
variable_upper_bounds::COBREXA.V,
18+
constraints::COBREXA.SM,
19+
lower_bounds::COBREXA.V,
20+
upper_bounds::COBREXA.V,
21+
epsilon::Float32 = COBREXA.configuration.sampler_tolerance,
22+
collect_iterations::Vector{Int},
23+
generator::StableRNG,
2424
direction_noise_max::Union{Nothing,Float32} = nothing,
25-
epsilon::Float32 = 1.0f-5,
26-
seed = Random.rand(UInt32),
2725
)
26+
# TODO
27+
2828
# allocate base helper variables
29-
npts = size(start, 2)
29+
npts = size(sample_c, 2)
3030
pts = cu(Matrix{Float32}(start))
3131
dirs = CUDA.zeros(size(start, 1), npts)
3232
lblambdas = CUDA.zeros(size(dirs))
@@ -145,4 +145,4 @@ function sample(
145145
collect(pts)
146146
end
147147

148-
end # module AffineHR
148+
export sample_chain_achr_cuda

src/AffineHR.jl renamed to src/affine_hr.jl

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
module AffineHR
2-
using ..CUDA
3-
using ..DocStringExtensions
4-
using SparseArrays
5-
6-
import ..COBREXA
7-
import ..TeaRNG
8-
import Random
91

102
function random_mix_matrix(npts, mix_points)
113
mtx = sparse(
@@ -48,19 +40,21 @@ present.
4840
If you are generating a sample of the optimal model solution, it is expected
4941
that the optimum bound is already present in `m`.
5042
51-
Returns a matrix of the same size as `start`.
43+
Returns blocks of the same size as `sample_c`.
5244
"""
53-
function sample(
54-
m::COBREXA.MetabolicModel,
55-
start::AbstractMatrix;
56-
iters::Int,
57-
bound_stoichiometry::Bool = false,
58-
check_stoichiometry::Bool = true,
59-
direction_noise_max::Union{Nothing,Float32} = nothing,
60-
epsilon::Float32 = 1.0f-5,
61-
seed = Random.rand(UInt32),
45+
function sample_chain_affine_hr_cuda(
46+
sample_c::COBREXA.M;
47+
variable_lower_bounds::COBREXA.V,
48+
variable_upper_bounds::COBREXA.V,
49+
constraints::COBREXA.SM,
50+
lower_bounds::COBREXA.V,
51+
upper_bounds::COBREXA.V,
52+
epsilon::Float32 = COBREXA.configuration.sampler_tolerance,
53+
collect_iterations::Vector{Int},
54+
generator::StableRNG,
6255
mix_points = 3,
63-
mix_mtx = random_mix_matrix(size(start, 2), mix_points),
56+
mix_mtx = random_mix_matrix(size(sample_c, 2), mix_points),
57+
direction_noise_max::Union{Nothing,Float32} = nothing,
6458
)
6559
# allocate base helper variables
6660
npts = size(start, 2)
@@ -183,5 +177,3 @@ function sample(
183177

184178
collect(pts)
185179
end
186-
187-
end # module AffineHR

src/FullAffineHR.jl renamed to src/full_affine_hr.jl

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
module FullAffineHR
2-
using ..CUDA
3-
using ..DocStringExtensions
4-
5-
import ..COBREXA
6-
import ..TeaRNG
7-
import Random
81

92
"""
103
$(TYPEDSIGNATURES)
@@ -19,16 +12,17 @@ Returns a matrix of `npts` samples organized in columns.
1912
This algorithm is mostly a toy for comparing the performance. It works, but do
2013
not use it in production.
2114
"""
22-
function sample(
23-
m::COBREXA.MetabolicModel,
24-
warmup::AbstractMatrix;
25-
npts::Int = size(warmup, 2),
26-
iters::Int,
27-
bound_stoichiometry::Bool = false,
28-
check_stoichiometry::Bool = true,
15+
function sample_chain_full_affine_hr_cuda(
16+
sample_c::COBREXA.M;
17+
variable_lower_bounds::COBREXA.V,
18+
variable_upper_bounds::COBREXA.V,
19+
constraints::COBREXA.SM,
20+
lower_bounds::COBREXA.V,
21+
upper_bounds::COBREXA.V,
22+
epsilon::Float32 = COBREXA.configuration.sampler_tolerance,
23+
collect_iterations::Vector{Int},
24+
generator::StableRNG,
2925
direction_noise_max::Union{Nothing,Float32} = nothing,
30-
epsilon::Float32 = 1.0f-5,
31-
seed = Random.rand(UInt32),
3226
)
3327
# TODO seed and tea iters
3428

@@ -159,5 +153,3 @@ function sample(
159153

160154
collect(pts)
161155
end
162-
163-
end # module AffineHR

src/TeaRNG.jl renamed to src/tea_rng.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
"""
2-
Fast stateless random number generator for GPUs based on TEA cipher.
3-
"""
4-
module TeaRNG
5-
using ..CUDA
6-
using ..DocStringExtensions
71

82
"""
93
$(TYPEDSIGNATURES)
@@ -60,5 +54,3 @@ function device_add_unif_rand!(arr, seed::UInt32, offset::Float32, scale::Float3
6054
end
6155
return
6256
end
63-
64-
end # module TeaRng

0 commit comments

Comments
 (0)