Skip to content

Commit

Permalink
Fix issue with the solver status method
Browse files Browse the repository at this point in the history
Fixes #24 and #25
  • Loading branch information
pablormier committed Aug 23, 2021
1 parent aa6a412 commit 9d9fed8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
6 changes: 3 additions & 3 deletions docs/examples/fastcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import miom
import numpy as np

# Use the flux-consistent subnetwork (fcm) of the Human1 GEM model
m = miom.mio.load_gem('https://github.com/pablormier/miom-gems/raw/main/gems/homo_sapiens_human1_fcm.miom')
m = miom.load_gem('@SysBioChalmers/Human-GEM/v1.9.0/consistent')
# Select reactions from the cholesterol metabolism as the core reactions to keep
core_rxn = m.find_reactions_from_pathway("Cholesterol metabolism")
print(sum(core_rxn))
Expand All @@ -25,8 +25,8 @@ weights[core_rxn == 1] = 1

# Exact-Fastcore
fmc = (miom
.load(m, solver=miom.Solvers.GUROBI_PYMIP)
.setup(opt_tol=0.01)
.load(m, solver=miom.Solvers.CPLEX)
.setup(opt_tol=0.02)
.steady_state()
.subset_selection(weights)
.keep(core_rxn == 1)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/fba.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A simple Flux Balance Analysis can be easily defined and solved with any of the

```python
import miom
network = miom.mio.load_gem("https://github.com/pablormier/miom-gems/raw/main/gems/mus_musculus_iMM1865.miom")
network = miom.mio.load_gem("@iMM1865")
target = "BIOMASS_reaction"
flux = (miom
.load(network)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/imat.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Example implementation of iMAT using MIOM. Note that this implementation support
import miom

# Use the iHuman-GEM model
m = miom.mio.load_gem('https://github.com/pablormier/miom-gems/raw/main/gems/homo_sapiens_human1.miom')
m = miom.load_gem('@SysBioChalmers/Human-GEM/v1.9.0')

# Add all the reactions from the Cholesterol pathway to the highly expressed set
RH = m.find_reactions_from_pathway("Cholesterol metabolism")
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/sparse_fba.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import miom
# Load a genome-scale metabolic network. You can load SMBL or Matlab metabolic networks
# as well using the same method, but it requires to have the cobratoolbox python library
# installed.
network = miom.mio.load_gem("https://github.com/pablormier/miom-gems/raw/main/gems/mus_musculus_iMM1865.miom")
network = miom.load_gem("@iMM1865")

# Create the sparse FBA problem to get a solution that maximizes
# the optimal flux through the BIOMASS_reaction minimizing the
Expand Down
17 changes: 6 additions & 11 deletions miom/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def convert_gem(args):
input = args.input
output = args.output
if isinstance(input, str):
if os.path.isfile(input):
if os.path.isfile(input) and input.endswith('.txt'):
# Open file and get all the lines into a list
print(f"Reading list of files from {input}...")
with open(input, "r") as f:
Expand All @@ -70,17 +70,12 @@ def convert_gem(args):
out_files.append(out_path.strip())
input = in_files
output = out_files
elif miom.mio._is_url(input):
print("Imporing file from URL")
input = [input]
else:
# Assume it's a folder
input_folder = os.path.abspath(input)
print("Input folder", input_folder)
# Check if folder is valid and exists:
if not os.path.isdir(input_folder):
raise FileNotFoundError(f"{input_folder} is not a valid folder, a file or an URL")
elif os.path.isdir(os.path.abspath(input)):
#in_folder = os.path.abspath(input)
input = [os.path.join(input, f) for f in os.listdir(input)]
else:
input = [input]
output = [output]
convert_list_gems(input, output, consistent=args.consistent, solver=args.solver)


Expand Down
12 changes: 11 additions & 1 deletion miom/miom.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ def initialize_problem(self):
def get_solver_status(self):
pass

@property
def status(self):
return self.get_solver_status()


@_composable
def setup(self, **kwargs):
"""Provide the options for the solver.
Expand Down Expand Up @@ -956,8 +961,13 @@ def _copy(self, **kwargs):
return m

def get_solver_status(self):
# Check if attribute solutions exist
if not hasattr(self, "solutions"):
status = "empty"
else:
status = self.solutions.claimedStatus
return {
"status": self.solutions.claimedStatus,
"status": status,
"objective_value": self.problem.value,
"elapsed_seconds": self.last_solver_time
}
Expand Down

0 comments on commit 9d9fed8

Please sign in to comment.