Skip to content

Commit

Permalink
testing and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
the-code-magician committed Jul 16, 2014
1 parent 6cd6296 commit 8f3042b
Show file tree
Hide file tree
Showing 13 changed files with 515 additions and 890 deletions.
26 changes: 20 additions & 6 deletions benchmarks/flux_analysis.py
Expand Up @@ -23,25 +23,39 @@
fva_setup = """
from cameo.flux_analysis.analysis import flux_variability_analysis
from cameo import config
from cameo.parallel import SequentialView
from cameo.parallel import SequentialView, MultiprocessingView
"""

config.default_view = SequentialView()
sequential_fva_statement = """
flux_variability_analysis(model, view=SequentialView())
"""

fva_statement = """
flux_variability_analysis(model)
#GLPK
glpk_sequential_fva_benchmark = Benchmark(sequential_fva_statement,
common_setup + fva_setup + glpk_model_setup,
start_date=datetime(2014, 7, 15))

#CPLEX
cplex_sequential_fva_benchmark = Benchmark(sequential_fva_statement,
common_setup + fva_setup + cplex_model_setup,
start_date=datetime(2014, 7, 15))


multiprocessing_fva_statement = """
flux_variability_analysis(model, view=MultiprocessingView())
"""

#GLPK
glpk_fva_benchmark = Benchmark(fva_statement,
glpk_multiprocessing_fva_benchmark = Benchmark(multiprocessing_fva_statement,
common_setup + fva_setup + glpk_model_setup,
start_date=datetime(2014, 7, 15))

#CPLEX
cplex_fva_benchmark = Benchmark(fva_statement,
cplex_multiprocessing_fva_benchmark = Benchmark(multiprocessing_fva_statement,
common_setup + fva_setup + cplex_model_setup,
start_date=datetime(2014, 7, 15))


######################
# Simulation methods #
######################
Expand Down
3 changes: 2 additions & 1 deletion cameo/parallel.py
Expand Up @@ -14,9 +14,10 @@

import Queue
from multiprocessing import Pool, cpu_count
from cameo.util import Singleton


class MultiprocessingView(object):
class MultiprocessingView(Singleton):

"""docstring for Parallel"""

Expand Down
7 changes: 3 additions & 4 deletions cameo/strain_design/heuristic/__init__.py
Expand Up @@ -105,7 +105,6 @@ def __init__(self, model=None, heuristic_method=inspyred.ec.GA, objective_functi
self.model = model
self.termination = termination
self._objective_function = objective_function
self._heuristic_method = heuristic_method
self.heuristic_method = heuristic_method
self._generator = None

Expand All @@ -115,7 +114,7 @@ def objective_function(self):

@objective_function.setter
def objective_function(self, objective_function):
if self._heuristic_method.__module__ == inspyred.ec.__name__ and isinstance(objective_function, list):
if self._heuristic_method.__module__ == inspyred.ec.ec.__name__ and isinstance(objective_function, list):
if len(objective_function) == 1:
self._objective_function = objective_function[0]
else:
Expand All @@ -133,7 +132,7 @@ def heuristic_method(self):
def heuristic_method(self, heuristic_method):
if heuristic_method.__module__ == inspyred.ec.emo.__name__ and not self.is_mo():
self._objective_function = [self.objective_function]
elif heuristic_method.__module__ == inspyred.ec.__name__ and self.is_mo():
elif heuristic_method.__module__ == inspyred.ec.ec.__name__ and self.is_mo():
if len(self.objective_function) == 1:
self._objective_function = self.objective_function[0]
else:
Expand Down Expand Up @@ -269,7 +268,7 @@ def run(self, **kwargs):
super(KnockoutOptimization, self).run(
distance_function=set_distance_function,
representation=self.representation,
max_candidate_size=self.max_size,
candidate_size=self.max_size,
variable_candidate_size=self.variable_size,
**kwargs)
return KnockoutOptimizationResult(model=self.model,
Expand Down
39 changes: 37 additions & 2 deletions cameo/strain_design/heuristic/generators.py
Expand Up @@ -15,8 +15,23 @@


def set_generator(random, args):
"""
Generates a list containing non-repeated elements of a discrete or
continuous representation.
:param random: Random()
:param args: dict
representation: set containing the possible values
max_candidate_size: int, default: 9
variable_candidate_size: bool, default: True
:return: candidate
A list containing a sample of the elements. If variable_candidate_size is
True the list size is up to max_candidate_size, otherwise the candidate
size equals candidate_size
"""
representation = args.get('representation')
max_size = args.get('max_candidate_size', 9)
max_size = args.get('candidate_size', 9)
variable_size = args.get('variable_candidate_size', True)
if variable_size:
size = random.randint(1, max_size)
Expand All @@ -28,8 +43,28 @@ def set_generator(random, args):

@diversify
def unique_set_generator(random, args):
"""
Generates a list containing non-repeated elements of a discrete or
continuous representation. When this generator is used, the population
will contain unique individuals.
See Also
--------
inspyred.ec.generators.diversify
:param random: Random()
:param args: dict
representation: set containing the possible values
max_candidate_size: int, default: 9
variable_candidate_size: bool, default: True
:return: candidate
A list containing a sample of the elements. If variable_candidate_size is
True the list size is up to max_candidate_size, otherwise the candidate
size equals candidate_size
"""
representation = args.get('representation')
max_size = args.get('max_candidate_size', 9)
max_size = args.get('candidate_size', 9)
variable_size = args.get('variable_candidate_size', True)
if variable_size:
size = random.randint(1, max_size)
Expand Down
2 changes: 1 addition & 1 deletion cameo/strain_design/heuristic/objective_functions.py
Expand Up @@ -73,7 +73,7 @@ class number_of_knockouts():

def __init__(self, sense='min'):
self.sense = sense
if sense == max:
if sense == 'max':
self.name = "max #knockouts"
else:
self.name = "min #knockouts"
Expand Down
12 changes: 12 additions & 0 deletions cameo/util.py
Expand Up @@ -19,6 +19,18 @@
import colorsys


class Singleton(object):
"""
Singleton class to be extended
"""
_instance = None

def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
return cls._instance


class AutoVivification(dict):

"""Implementation of perl's autovivification feature. Checkout http://stackoverflow.com/a/652284/280182"""
Expand Down

0 comments on commit 8f3042b

Please sign in to comment.