Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octuple-precision #52

Merged
merged 36 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
37d71ed
Update Consistency Checking modules with optional OctuplePrecision in…
iManGHD Apr 17, 2024
4563203
Implement optional OctuplePrecision input in distributedQFCA.jl and Q…
iManGHD Apr 18, 2024
08399ad
Update distributedReversibility Correction
iManGHD Apr 19, 2024
3190d17
Update QuantomeReducer to use One Model for Reduction
iManGHD Apr 19, 2024
7504d1f
Update QuantomeReducer with BiGFloat precision
iManGHD Apr 19, 2024
b320af7
Update Project.toml to add Clarabel and CDDLib
iManGHD Apr 19, 2024
d87efc6
Update Project.toml
iManGHD Apr 19, 2024
c626277
Update sparseQFCA.png
iManGHD Apr 19, 2024
946c4d5
Delete example/sparseQFCA.png
iManGHD Apr 19, 2024
b858c58
Add sparseQFCA.png
iManGHD Apr 19, 2024
088f659
Update Project.toml
iManGHD Apr 19, 2024
7a331cb
Update Project.toml
iManGHD Apr 21, 2024
818f768
Update Project.toml
iManGHD Apr 21, 2024
7c6b8b3
Update Project.toml
iManGHD Apr 21, 2024
ae3d422
Update Project.toml
iManGHD Apr 21, 2024
ef90584
Update Project.toml
iManGHD Apr 21, 2024
82299f4
Update Project.toml
iManGHD Apr 21, 2024
79a7839
Update Project.toml
iManGHD Apr 21, 2024
708620e
Update Project.toml
iManGHD Apr 23, 2024
5c03a39
Update Project.toml
iManGHD Apr 23, 2024
33a5b61
Update Project.toml
iManGHD Apr 23, 2024
0ab21f9
Update Project.toml
iManGHD Apr 23, 2024
9034796
Update Project.toml
iManGHD Apr 23, 2024
60f97b3
Update Project.toml
iManGHD Apr 24, 2024
3d5b150
Update Project.toml for GLPK compatibility
iManGHD Apr 25, 2024
e21228a
Update Project.toml for MathOptInterface
iManGHD Apr 25, 2024
53d668f
Update Project.toml
iManGHD Apr 25, 2024
827aed3
Update Project.toml
iManGHD Apr 28, 2024
ab936bc
Update documentation.yml
iManGHD May 1, 2024
e6cccc2
Update documentation.yml
iManGHD May 16, 2024
86af42c
Update documentation.yml
iManGHD May 17, 2024
636b120
Update codecov.yml
iManGHD May 17, 2024
59c988e
Update documentation.yml
iManGHD May 17, 2024
4d112ca
Update documentation.yml
iManGHD May 17, 2024
2bed062
Update documentation.yml
iManGHD May 17, 2024
f7e0b91
Update documentation.yml
iManGHD May 20, 2024
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
5 changes: 5 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
steps:
- uses: actions/checkout@master
- name: Generate Coverage Data
run: |
JULIA_COVERAGE=true julia runtests.jl
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
commit: HEAD~5..HEAD # Analyze the last 5 commits

2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: '1.4'
version: '1.9.2' # Specify the required Julia version here
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
Expand Down
17 changes: 11 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "sparseQFCA"
uuid = "077cf62c-ad2d-5edd-99ec-638372f8b004"
authors = ["Mojtaba Tefagh <mtefagh@sharif.edu>", "Iman Ghadimi <iman.diligent@gmail.com>"]
version = "1.9.0"
version = "2.0.0"

[deps]
COBREXA = "babc4406-5200-4a30-9033-bf5ae714c842"
Expand All @@ -14,10 +14,15 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
Clarabel = "61c947e1-3e6d-4ee4-985a-eec8c727bd6e"
CDDLib = "3391f64e-dcde-5f30-b752-e11513730f60"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

[compat]
COBREXA = "1.0, 1.2"
Colors = "0.12"
GLPK = "0.14, 1.0"
JuMP = "0.21, 1.0"
julia = "1.8, 1.9"
COBREXA = "1.5.1"
MathOptInterface = "1.28.1"
GLPK = "1.1.3"
Clarabel = "0.7.1"
Colors = "0.12.10"
JuMP = "1.21.1"
julia = "1.9.2"
Binary file modified example/sparseQFCA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions src/ConsistencyChecking/SwiftCC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module SwiftCC

export Model_CC, model_CC_Constructor, swiftCC

using GLPK, JuMP, COBREXA, LinearAlgebra, SparseArrays, Distributed
using GLPK, JuMP, COBREXA, LinearAlgebra, SparseArrays, Distributed, Clarabel

import CDDLib

include("../Pre_Processing/Pre_processing.jl")

Expand Down Expand Up @@ -66,7 +68,7 @@ and assigns values to its fields based on the other arguments passed in.
"""

function model_CC_Constructor(ModelObject_CC::Model_CC, S::Union{SparseMatrixCSC{Float64,Int64}, AbstractMatrix}, Metabolites::Array{String,1},
Reactions::Array{String,1}, Genes::Array{String,1},m::Int, n::Int, lb::Array{Float64,1}, ub::Array{Float64,1})
Reactions::Array{String,1}, Genes::Array{String,1}, m::Int, n::Int, lb::Array{Float64,1}, ub::Array{Float64,1})
ModelObject_CC.S = S
ModelObject_CC.Metabolites = Metabolites
ModelObject_CC.Reactions = Reactions
Expand Down Expand Up @@ -111,7 +113,7 @@ See also: `Model_CC`, `model_CC_Constructor()`, `reversibility()`

"""

function swiftCC(ModelObject_CC::Model_CC, Tolerance::Float64=1e-6, printLevel::Int=1)
function swiftCC(ModelObject_CC::Model_CC, Tolerance::Float64=1e-6, OctuplePrecision::Bool=false, printLevel::Int=1)

## Extract relevant information from the input model object

Expand All @@ -127,6 +129,7 @@ function swiftCC(ModelObject_CC::Model_CC, Tolerance::Float64=1e-6, printLevel::

# Create an array of reaction IDs:
Reaction_Ids = collect(1:n)

irreversible_reactions_id, reversible_reactions_id = reversibility(lb, Reaction_Ids, 0)
n_irr = length(irreversible_reactions_id)
n_rev = length(reversible_reactions_id)
Expand All @@ -138,7 +141,13 @@ function swiftCC(ModelObject_CC::Model_CC, Tolerance::Float64=1e-6, printLevel::
ub_u = ones(n_irr)

# Create a new optimization model using the GLPK optimizer:
model = Model(GLPK.Optimizer)
if OctuplePrecision
model = GenericModel{BigFloat}(Clarabel.Optimizer{BigFloat})
settings = Clarabel.Settings()
settings = Clarabel.Settings(verbose = false, time_limit = 5)
else
model = Model(GLPK.Optimizer)
end

# Define variables V and u with their lower and upper bounds:
@variable(model, lb[i] <= V[i = 1:n] <= ub[i])
Expand Down
26 changes: 21 additions & 5 deletions src/ConsistencyChecking/TheNaiveApproach.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module TheNaiveApproach

export find_blocked_reactions

using GLPK, JuMP, COBREXA, Distributed
using GLPK, JuMP, COBREXA, Distributed, Clarabel

import CDDLib

include("../Pre_Processing/Pre_processing.jl")

Expand Down Expand Up @@ -52,7 +54,7 @@ See also: `dataOfModel()`, `reversibility()`

"""

function find_blocked_reactions(model::CoreModel, Tolerance::Float64=1e-6, printLevel::Int=1)
function find_blocked_reactions(model::CoreModel, Tolerance::Float64=1e-6, OctuplePrecision::Bool=false, printLevel::Int=1)

## Export data from model

Expand All @@ -71,7 +73,7 @@ function find_blocked_reactions(model::CoreModel, Tolerance::Float64=1e-6, print
printstyled("Homogenization:\n"; color=:cyan)

# Set the maximum value for M:
M = 1000000.0
M = getM()

## Loop through each value in the array "lb" and "ub"

Expand Down Expand Up @@ -101,7 +103,14 @@ function find_blocked_reactions(model::CoreModel, Tolerance::Float64=1e-6, print
irreversible_unblocked_reactions_id = []

# Create a new optimization model using the GLPK optimizer:
model_irr = Model(GLPK.Optimizer)

if OctuplePrecision
model_irr = GenericModel{BigFloat}(Clarabel.Optimizer{BigFloat})
settings = Clarabel.Settings()
settings = Clarabel.Settings(verbose = false, time_limit = 5)
else
model_irr = Model(GLPK.Optimizer)
end

# Define the variable V for each reaction, with its lower and upper bounds:
@variable(model_irr, lb[i] <= V[i = 1:n] <= ub[i])
Expand Down Expand Up @@ -143,7 +152,14 @@ function find_blocked_reactions(model::CoreModel, Tolerance::Float64=1e-6, print
reversible_blocked_reactions_id = []

# Create a new optimization model using the GLPK optimizer:
model_rev = Model(GLPK.Optimizer)

if OctuplePrecision
model_rev = GenericModel{BigFloat}(Clarabel.Optimizer{BigFloat})
settings = Clarabel.Settings()
settings = Clarabel.Settings(verbose = false, time_limit = 5)
else
model_rev = Model(GLPK.Optimizer)
end

# Define the variable V for each reaction, with its lower and upper bounds:
@variable(model_rev, lb[i] <= V[i = 1:n] <= ub[i])
Expand Down
92 changes: 53 additions & 39 deletions src/Pre_Processing/Pre_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module Pre_processing

export dataOfModel, getM, getTolerance, reversibility, check_duplicate_reactions, homogenization, remove_zeroRows, Model_Correction, model_Correction_Constructor, distributedReversibility_Correction

using GLPK, JuMP, COBREXA, SparseArrays, Distributed, SharedArrays, Distributed
using GLPK, JuMP, COBREXA, SparseArrays, Distributed, SharedArrays, Distributed, Clarabel

import CDDLib

"""
dataOfModel(model)
Expand Down Expand Up @@ -549,7 +551,7 @@ See also: `dataOfModel()`, `reversibility()`, `homogenization()`, 'getTolerance(

"""

function distributedReversibility_Correction(ModelObject_Correction::Model_Correction, blocked_index_rev::Vector{Int64}, printLevel::Int=1)
function distributedReversibility_Correction(ModelObject_Correction::Model_Correction, blocked_index_rev::Vector{Int64}, OctuplePrecision::Bool=false, printLevel::Int=1)

## Extract relevant information from the input model object

Expand All @@ -563,7 +565,7 @@ function distributedReversibility_Correction(ModelObject_Correction::Model_Corre
n = length(lb)

# Set the tolerance value:
Tolerance = 1e-6
Tolerance = getTolerance()

# Initialize empty arrays to store the IDs of blocked reversible reactions in the forward and backward directions:
rev_blocked_fwd = Array{Int64}([])
Expand All @@ -576,53 +578,65 @@ function distributedReversibility_Correction(ModelObject_Correction::Model_Corre
# Iterate over all reversible reactions in the model:
@sync @distributed for i in reversible_reactions_id

if i in blocked_index_rev
Correction[i,i] = +2.0
continue
# Create a local model object for each worker process:
if OctuplePrecision
local_model = GenericModel{BigFloat}(Clarabel.Optimizer{BigFloat})
settings = Clarabel.Settings()
settings = Clarabel.Settings(verbose = false, time_limit = 5)
else

# Create a local model object for each worker process:
local_model = Model(GLPK.Optimizer)
end

# Define variables V:
@variable(local_model, lb[i] <= V[i = 1:n] <= ub[i])
# Define variables V:
@variable(local_model, lb[i] <= V[i = 1:n] <= ub[i])

# Add the stoichiometric constraints to the model:
@constraint(local_model, S * V .== 0)
# Add the stoichiometric constraints to the model:
@constraint(local_model, S * V .== 0)

# Set the objective function to maximize the flux through reaction i in the forward direction:
@objective(local_model, Max, V[i])
# Set the objective function to maximize the flux through reaction i in the forward direction:
@objective(local_model, Max, V[i])

# Add a constraint that limits the flux through reaction i in the forward direction to be less than or equal to 1:
@constraint(local_model, V[i] <= 1)
# Add a constraint that limits the flux through reaction i in the forward direction to be less than or equal to 1:
@constraint(local_model, c_irr, V[i] <= 1)

# Optimize the model and retrieve the objective value:
optimize!(local_model)
opt_fwd = objective_value(local_model)
# Optimize the model and retrieve the objective value:
optimize!(local_model)
opt_fwd = objective_value(local_model)

# Set the objective function to minimize the flux through reaction i in the backward direction:
@objective(local_model, Min, V[i])
# Remove the current constraint from the model:
delete(local_model, c_irr)

# Add a constraint that limits the flux through reaction i in the backward direction to be greater than or equal to -1:
@constraint(local_model, V[i] >= -1)
# Unregister the current constraint from the model:
unregister(local_model, :c_irr)

# Optimize the model and retrieve the objective value:
optimize!(local_model)
opt_back = objective_value(local_model)
# Set the objective function to minimize the flux through reaction i in the backward direction:
@objective(local_model, Min, V[i])

# The reaction is considered to be blocked:
if isapprox(opt_fwd, 0, atol=Tolerance) && isapprox(opt_back, 0, atol=Tolerance)
Correction[i,i] = +2.0
continue
# If the objective value is approximately 0, the reaction is considered to be blocked in the forward direction:
elseif isapprox(opt_fwd, 0, atol=Tolerance)
Correction[i,i] = +1.0
# If the objective value is approximately 0, the reaction is considered to be blocked in the backward direction:
elseif isapprox(opt_back, 0, atol=Tolerance)
Correction[i,i] = -1.0
else
continue
end
# Add a constraint that limits the flux through reaction i in the backward direction to be greater than or equal to -1:
@constraint(local_model, c_rev, V[i] >= -1)

# Optimize the model and retrieve the objective value:
optimize!(local_model)
opt_back = objective_value(local_model)

# Remove the current constraint from the model:
delete(local_model, c_rev)

# Unregister the current constraint from the model:
unregister(local_model, :c_rev)

# The reaction is considered to be blocked:
if isapprox(opt_fwd, 0, atol=Tolerance) && isapprox(opt_back, 0, atol=Tolerance)
Correction[i,i] = +2.0
continue
# If the objective value is approximately 0, the reaction is considered to be blocked in the forward direction:
elseif isapprox(opt_fwd, 0, atol=Tolerance)
Correction[i,i] = +1.0
# If the objective value is approximately 0, the reaction is considered to be blocked in the backward direction:
elseif isapprox(opt_back, 0, atol=Tolerance)
Correction[i,i] = -1.0
else
continue
end

end
Expand Down
6 changes: 3 additions & 3 deletions src/QFCA/distributedQFCA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ See also: `dataOfModel()`, `reversibility()`, `homogenization()`, `Model_QFCA`,

"""

function distributedQFCA(ModelObject_QFCA::Model_QFCA, blocked_index::Vector{Int64}, removing::Bool=false, Tolerance::Float64=1e-6, printLevel::Int=1)
function distributedQFCA(ModelObject_QFCA::Model_QFCA, blocked_index::Vector{Int64}, removing::Bool=false, Tolerance::Float64=1e-6, OctuplePrecision::Bool=false, printLevel::Int=1)


## Extract relevant information from the input model object
Expand Down Expand Up @@ -217,7 +217,7 @@ function distributedQFCA(ModelObject_QFCA::Model_QFCA, blocked_index::Vector{Int

# Calculate the set of blocked reactions and dual variables for the modified network:
model_CC_Constructor(ModelObject_CC ,S_noBlocked, Metabolites, Reactions_noBlocked, Genes, row_noBlocked, col_noBlocked, lb_noBlocked, ub_noBlocked)
blocked, ν = swiftCC(ModelObject_CC, Tolerance, 0)
blocked, ν = swiftCC(ModelObject_CC, Tolerance, OctuplePrecision, 0)

# Update indices of blocked reactions after removing ith reaction:
for j = 1:length(blocked)
Expand Down Expand Up @@ -248,7 +248,7 @@ function distributedQFCA(ModelObject_QFCA::Model_QFCA, blocked_index::Vector{Int

# Find the set of blocked reactions and dual variables for the modified network:
model_CC_Constructor(ModelObject_CC ,S_noBlocked, Metabolites, Reactions_noBlocked, Genes, row_noBlocked, col_noBlocked, lb_noBlocked, ub_noBlocked)
blocked, ν = swiftCC(ModelObject_CC, Tolerance, 0)
blocked, ν = swiftCC(ModelObject_CC, Tolerance, OctuplePrecision, 0)

# Update DC_Matrix based on the blocked reactions:
DC_Matrix[i,blocked] .= 1.0
Expand Down
Loading
Loading