Skip to content

Commit

Permalink
start migration to cobrexa2
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Jun 19, 2024
1 parent 8ab5549 commit 3eb456d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 72 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CuFluxSampler"
uuid = "d04bc951-f907-4aa3-859a-fc6f9fe5eea9"
authors = ["Mirek Kratochvil <[email protected]>"]
version = "0.1.0"
version = "0.2.0"

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

[compat]
COBREXA = "1"
CUDA = "4"
COBREXA = "2"
CUDA = "5"
DocStringExtensions = "0.9"
julia = "1.6"

Expand Down
9 changes: 5 additions & 4 deletions src/CuFluxSampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ using DocStringExtensions
import COBREXA
import CUDA
import SparseArrays
import StableRNGs: StableRNG

include("TeaRNG.jl")
include("FullAffineHR.jl")
include("AffineHR.jl")
include("ACHR.jl")
include("tea_rng.jl")
include("full_affine_hr.jl")
include("affine_hr.jl")
include("achr.jl")

end # module CuFluxSampler
36 changes: 18 additions & 18 deletions src/ACHR.jl → src/achr.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
module ACHR
using ..CUDA
using ..DocStringExtensions
using SparseArrays

import ..COBREXA
import ..TeaRNG
import Random

"""
$(TYPEDSIGNATURES)
A traditional artificially-centered hit-and-run algorithm that starts with
`start` points.
To use this on a model, use [`flux_sample`](@ref) or
[`sample_constraints`](@ref); most parameters are filled in correctly by these
functions.
Refer to the documentation in module AffineHR for the meaning of arguments.
"""
function sample(
m::COBREXA.MetabolicModel,
start::AbstractMatrix;
iters::Int,
bound_stoichiometry::Bool = false,
check_stoichiometry::Bool = true,
function sample_chain_achr_cuda(
sample_c::COBREXA.M;
variable_lower_bounds::COBREXA.V,
variable_upper_bounds::COBREXA.V,
constraints::COBREXA.SM,
lower_bounds::COBREXA.V,
upper_bounds::COBREXA.V,
epsilon::Float32 = COBREXA.configuration.sampler_tolerance,
collect_iterations::Vector{Int},
generator::StableRNG,
direction_noise_max::Union{Nothing,Float32} = nothing,
epsilon::Float32 = 1.0f-5,
seed = Random.rand(UInt32),
)
# TODO

# allocate base helper variables
npts = size(start, 2)
npts = size(sample_c, 2)
pts = cu(Matrix{Float32}(start))
dirs = CUDA.zeros(size(start, 1), npts)
lblambdas = CUDA.zeros(size(dirs))
Expand Down Expand Up @@ -145,4 +145,4 @@ function sample(
collect(pts)
end

end # module AffineHR
export sample_chain_achr_cuda
34 changes: 13 additions & 21 deletions src/AffineHR.jl → src/affine_hr.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
module AffineHR
using ..CUDA
using ..DocStringExtensions
using SparseArrays

import ..COBREXA
import ..TeaRNG
import Random

function random_mix_matrix(npts, mix_points)
mtx = sparse(
Expand Down Expand Up @@ -48,19 +40,21 @@ present.
If you are generating a sample of the optimal model solution, it is expected
that the optimum bound is already present in `m`.
Returns a matrix of the same size as `start`.
Returns blocks of the same size as `sample_c`.
"""
function sample(
m::COBREXA.MetabolicModel,
start::AbstractMatrix;
iters::Int,
bound_stoichiometry::Bool = false,
check_stoichiometry::Bool = true,
direction_noise_max::Union{Nothing,Float32} = nothing,
epsilon::Float32 = 1.0f-5,
seed = Random.rand(UInt32),
function sample_chain_affine_hr_cuda(
sample_c::COBREXA.M;
variable_lower_bounds::COBREXA.V,
variable_upper_bounds::COBREXA.V,
constraints::COBREXA.SM,
lower_bounds::COBREXA.V,
upper_bounds::COBREXA.V,
epsilon::Float32 = COBREXA.configuration.sampler_tolerance,
collect_iterations::Vector{Int},
generator::StableRNG,
mix_points = 3,
mix_mtx = random_mix_matrix(size(start, 2), mix_points),
mix_mtx = random_mix_matrix(size(sample_c, 2), mix_points),
direction_noise_max::Union{Nothing,Float32} = nothing,
)
# allocate base helper variables
npts = size(start, 2)
Expand Down Expand Up @@ -183,5 +177,3 @@ function sample(

collect(pts)
end

end # module AffineHR
28 changes: 10 additions & 18 deletions src/FullAffineHR.jl → src/full_affine_hr.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
module FullAffineHR
using ..CUDA
using ..DocStringExtensions

import ..COBREXA
import ..TeaRNG
import Random

"""
$(TYPEDSIGNATURES)
Expand All @@ -19,16 +12,17 @@ Returns a matrix of `npts` samples organized in columns.
This algorithm is mostly a toy for comparing the performance. It works, but do
not use it in production.
"""
function sample(
m::COBREXA.MetabolicModel,
warmup::AbstractMatrix;
npts::Int = size(warmup, 2),
iters::Int,
bound_stoichiometry::Bool = false,
check_stoichiometry::Bool = true,
function sample_chain_full_affine_hr_cuda(
sample_c::COBREXA.M;
variable_lower_bounds::COBREXA.V,
variable_upper_bounds::COBREXA.V,
constraints::COBREXA.SM,
lower_bounds::COBREXA.V,
upper_bounds::COBREXA.V,
epsilon::Float32 = COBREXA.configuration.sampler_tolerance,
collect_iterations::Vector{Int},
generator::StableRNG,
direction_noise_max::Union{Nothing,Float32} = nothing,
epsilon::Float32 = 1.0f-5,
seed = Random.rand(UInt32),
)
# TODO seed and tea iters

Expand Down Expand Up @@ -159,5 +153,3 @@ function sample(

collect(pts)
end

end # module AffineHR
8 changes: 0 additions & 8 deletions src/TeaRNG.jl → src/tea_rng.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
"""
Fast stateless random number generator for GPUs based on TEA cipher.
"""
module TeaRNG
using ..CUDA
using ..DocStringExtensions

"""
$(TYPEDSIGNATURES)
Expand Down Expand Up @@ -60,5 +54,3 @@ function device_add_unif_rand!(arr, seed::UInt32, offset::Float32, scale::Float3
end
return
end

end # module TeaRng

0 comments on commit 3eb456d

Please sign in to comment.