Exemplo n.º 1
0
        def test_length(self):
            self.assertEqual(len(self.view), cpu_count())

            view = MultiprocessingView(4)
            self.assertEqual(len(view), 4)

            view = MultiprocessingView(processes=3)
            self.assertEqual(len(view), 3)
Exemplo n.º 2
0
 def test_flux_variability_parallel(self):
     mp_view = MultiprocessingView()
     fva_solution = flux_variability_analysis(self.model,
                                              remove_cycles=False,
                                              view=mp_view)
     mp_view.shutdown()
     assert_dataframes_equal(fva_solution,
                             REFERENCE_FVA_SOLUTION_ECOLI_CORE)
Exemplo n.º 3
0
 def test_one_variable_parallel(self):
     ppp = phenotypic_phase_plane(self.model,
                                  ['EX_o2_LPAREN_e_RPAREN_'],
                                  view=MultiprocessingView())
     assert_dataframes_equal(ppp, REFERENCE_PPP_o2_EcoliCore)
     ppp = phenotypic_phase_plane(self.model,
                                  'EX_o2_LPAREN_e_RPAREN_',
                                  view=MultiprocessingView())
     assert_dataframes_equal(ppp, REFERENCE_PPP_o2_EcoliCore)
Exemplo n.º 4
0
    def test_length(self):
        view = MultiprocessingView()
        assert len(view) == cpu_count()

        view = MultiprocessingView(4)
        assert len(view) == 4

        view = MultiprocessingView(processes=3)
        assert len(view) == 3
Exemplo n.º 5
0
 def test_flux_variability_parallel(self, core_model):
     original_objective = core_model.objective
     mp_view = MultiprocessingView(2)
     fva_solution = flux_variability_analysis(core_model, fraction_of_optimum=0.999999419892,
                                              remove_cycles=False, view=mp_view)
     pfba_fva = flux_variability_analysis(core_model, fraction_of_optimum=1, pfba_factor=1,
                                          view=mp_view).data_frame
     mp_view.shutdown()
     assert_data_frames_equal(fva_solution, REFERENCE_FVA_SOLUTION_ECOLI_CORE)
     assert original_objective == core_model.objective
     assert sum(abs(pfba_fva.lower_bound)) - 518.422 < .001
     assert sum(abs(pfba_fva.upper_bound)) - 518.422 < .001
Exemplo n.º 6
0
 def test_flux_variability_parallel(self, core_model):
     original_objective = core_model.objective
     mp_view = MultiprocessingView(2)
     fva_solution = flux_variability_analysis(core_model, fraction_of_optimum=0.999999419892,
                                              remove_cycles=False, view=mp_view)
     pfba_fva = flux_variability_analysis(core_model, fraction_of_optimum=1, pfba_factor=1,
                                          view=mp_view).data_frame
     mp_view.shutdown()
     assert_data_frames_equal(fva_solution, REFERENCE_FVA_SOLUTION_ECOLI_CORE)
     assert original_objective == core_model.objective
     assert sum(abs(pfba_fva.lower_bound)) - 518.422 < .001
     assert sum(abs(pfba_fva.upper_bound)) - 518.422 < .001
Exemplo n.º 7
0
def cameo_optim(isMultiProc, size):
    model = read_sbml_model(SBML_FILE)
    obj = biomass_product_coupled_yield(
        model.reactions.Ec_biomass_iAF1260_core_59p81M,
        model.reactions.EX_succ_e_, model.reactions.EX_glc_e_)
    ko = ReactionKnockoutOptimization(model=model,
                                      objective_function=obj,
                                      use_nullspace_simplification=False)
    if isMultiProc:
        res = ko.run(pop_size=100,
                     max_generations=1,
                     max_size=size,
                     crossover_rate=0.9,
                     mutation_rate=0.1,
                     indel_rate=0.185,
                     view=MultiprocessingView(processes=2))
    else:
        res = ko.run(pop_size=100,
                     max_generations=1,
                     max_size=size,
                     crossover_rate=0.9,
                     mutation_rate=0.1,
                     indel_rate=0.185)

    res.data_frame.to_csv(basePath + "Results/optim_Ec_iAF1260_ko_cameo.csv")
Exemplo n.º 8
0
 def test_two_variables_parallel(self, core_model):
     ppp2d = phenotypic_phase_plane(
         core_model, ['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'],
         view=MultiprocessingView())
     assert_data_frames_equal(
         ppp2d,
         REFERENCE_PPP_o2_glc_EcoliCore,
         sort_by=['EX_o2_LPAREN_e_RPAREN_', 'EX_glc_LPAREN_e_RPAREN_'])
Exemplo n.º 9
0
    class TestMultiprocessingView(unittest.TestCase):
        def setUp(self):
            self.view = MultiprocessingView()

        def test_map(self):
            self.assertEqual(self.view.map(to_the_power_of_2, list(range(100))), SOLUTION)

        def test_apply(self):
            for i in range(100):
                self.assertEqual(self.view.apply(to_the_power_of_2, i), SOLUTION[i])

        def test_length(self):
            self.assertEqual(len(self.view), cpu_count())

            view = MultiprocessingView(4)
            self.assertEqual(len(view), 4)

            view = MultiprocessingView(processes=3)
            self.assertEqual(len(view), 3)
Exemplo n.º 10
0
    class TestMultiprocessingView(unittest.TestCase):
        def setUp(self):
            self.view = MultiprocessingView()

        def test_map(self):
            self.assertEqual(
                self.view.map(to_the_power_of_2, list(range(100))), SOLUTION)

        def test_apply(self):
            for i in range(100):
                self.assertEqual(self.view.apply(to_the_power_of_2, i),
                                 SOLUTION[i])

        def test_length(self):
            self.assertEqual(len(self.view), cpu_count())

            view = MultiprocessingView(4)
            self.assertEqual(len(view), 4)

            view = MultiprocessingView(processes=3)
            self.assertEqual(len(view), 3)
Exemplo n.º 11
0
 def test_flux_variability_parallel_remove_cycles(self):
     fva_solution = flux_variability_analysis(self.model, fraction_of_optimum=0.999999419892,
                                              remove_cycles=True, view=MultiprocessingView())
     self.assertGreater(REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound']['FRD7'], 666.)
     self.assertAlmostEqual(fva_solution['upper_bound']['FRD7'], 0.)
     for key in fva_solution.data_frame.index:
         if REFERENCE_FVA_SOLUTION_ECOLI_CORE['lower_bound'][key] > -666:
             self.assertAlmostEqual(fva_solution['lower_bound'][key],
                                    REFERENCE_FVA_SOLUTION_ECOLI_CORE['lower_bound'][key], delta=0.0001)
         if REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound'][key] < 666:
             self.assertAlmostEqual(fva_solution['upper_bound'][key],
                                    REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound'][key], delta=0.0001)
Exemplo n.º 12
0
 def test_flux_variability_parallel_remove_cycles(self, core_model):
     original_objective = core_model.objective
     fva_solution = flux_variability_analysis(core_model, fraction_of_optimum=0.999999419892,
                                              remove_cycles=True, view=MultiprocessingView())
     assert REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound']['FRD7'] > 666.
     assert round(abs(fva_solution['upper_bound']['FRD7'] - 0.), 7) == 0
     for key in fva_solution.data_frame.index:
         if REFERENCE_FVA_SOLUTION_ECOLI_CORE['lower_bound'][key] > -666:
             assert abs(
                 fva_solution['lower_bound'][key] - REFERENCE_FVA_SOLUTION_ECOLI_CORE['lower_bound'][key]) < 0.0001
         if REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound'][key] < 666:
             assert abs(
                 fva_solution['upper_bound'][key] - REFERENCE_FVA_SOLUTION_ECOLI_CORE['upper_bound'][key]) < 0.0001
     assert original_objective == core_model.objective
Exemplo n.º 13
0
from __future__ import absolute_import, print_function

import os
import warnings
from multiprocessing import cpu_count
from multiprocessing.queues import Full, Empty

import pytest

from cameo.parallel import SequentialView

views = [SequentialView()]

try:
    from cameo.parallel import MultiprocessingView
    views.append(MultiprocessingView())
except ImportError:
    MultiprocessingView = None

try:
    from cameo.parallel import RedisQueue
except ImportError:
    RedisQueue = None

try:
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        from IPython.parallel import Client, interactive
except ImportError:
    try:
        from ipyparallel import Client, interactive
Exemplo n.º 14
0
 def test_flux_variability_parallel(self):
     mp_view = MultiprocessingView()
     fva_solution = flux_variability_analysis(self.model, remove_cycles=False, view=mp_view)
     mp_view.shutdown()
     assert_dataframes_equal(fva_solution, REFERENCE_FVA_SOLUTION_ECOLI_CORE)
Exemplo n.º 15
0
Arquivo: cli.py Projeto: weif000/cameo
def design(product, host, output, format, cores, aerobic, differential_fva,
           heuristic_optimization, max_pathway_predictions,
           differential_fva_points, pathway_prediction_timeout,
           heuristic_optimization_timeout, logging):
    """Compute strain designs for desired product."""
    from cameo.api.designer import design
    from cameo.api.hosts import hosts
    from cameo.parallel import MultiprocessingView, SequentialView

    logger.setLevel(logging)
    cameo_logger.setLevel(logging)

    hosts = [getattr(hosts, host) for host in host]

    if cores > 1:
        if sys.platform == 'darwin':  # check if numpy is compatible with multiprocessing
            logger.debug(
                'On OS X, testing if numpy is compatible with multiprocessing')
            import numpy
            logger.debug('numpy.config: {}'.format(
                numpy.__config__.blas_opt_info))
            if 'Accelerate' in str(numpy.__config__.blas_opt_info):
                click.echo(click.style(
                    'WARNING! It looks like the present installation of numpy '
                    'is linked against the accelerate framework, which '
                    'unfortunately is incompatible with multiprocessing'
                    'and might cause the program to hang at some point. '
                    'Either set --cores 1 to run sequentially or consider '
                    'installing numpy via conda (https://conda.io/docs/installation.html), '
                    'which should fix this issue. \n'
                    'Proceed with caution ...',
                    fg='red'),
                           err=True)
                click.confirm('Do you want to proceed?', abort=True)

        view = MultiprocessingView(processes=cores)
    elif cores == 1:
        view = SequentialView()

    design.options.pathway_prediction_timeout = pathway_prediction_timeout * 60
    design.options.heuristic_optimization_timeout = heuristic_optimization_timeout
    design.options.max_pathway_predictions = max_pathway_predictions
    design.options.differential_fva = differential_fva
    design.options.heuristic_optimization = heuristic_optimization
    design.options.differential_fva_points = differential_fva_points

    results = design(product=product, hosts=hosts, view=view, aerobic=aerobic)
    click.echo(results)

    for output, format in zip(output, format):
        if format == 'pickle':
            click.echo('Pickling results into {}'.format(output))
            with open(output, 'wb') as f:
                pickle.dump(results, f)
        else:
            click.echo('Writing results into {} using format "{}"'.format(
                output, format))
            results[
                'heterologous_pathway'] = results.heterologous_pathway.apply(
                    str)
            results['manipulations'] = results.manipulations.apply(str)
            OUTPUT_WRITER[format](results, output)

    click.echo(results)
Exemplo n.º 16
0
 def setUp(self):
     self.view = MultiprocessingView()
Exemplo n.º 17
0
    def default(self):
        product = None
        output_format = None
        auto_select = self.app.pargs.yes_all

        if self.app.pargs.product is None:
            print("Argument --product must be provided")
            exit(1)
        else:
            product = self.app.pargs.product

        if self.app.pargs.output_format is None:
            if auto_select:
                output_format = "xlsx"
                print("Output format will be Excel")
            else:
                formats = [
                    "%i - %s (.%s)\n" %
                    (i + 1, OUTPUT_FORMATS_EXPLANATION[ext], ext)
                    for i, ext in enumerate(VALID_OUTPUT_FORMATS)
                ]

                choice = input("Choose your output format:\n" +
                               "".join(formats) + "Enter [1]:")
                if choice == "":
                    choice = "1"
                try:
                    choice = int(choice)
                    output_format = VALID_OUTPUT_FORMATS[choice - 1]
                except TypeError:
                    print("Invalid choice %s" % choice)
                    exit(1)

        else:
            output_format = self.app.pargs.output_format

        if output_format not in VALID_OUTPUT_FORMATS:
            print("Invalid input format")

        if self.app.pargs.output is None:
            output = self.app.pargs.product + "." + output_format
            if auto_select:
                print("Output will be written to %s" % output)
            else:
                choice = input("Enter your output path (%s):" % output)
                if choice != "":
                    output = choice
        else:
            output = self.app.pargs.output

        if self.app.pargs.host is None:
            _hosts = ['ecoli', 'yeast']
        else:
            _hosts = self.app.pargs.host

        _hosts = [getattr(hosts, host) for host in _hosts]

        if self.app.pargs.multiprocess:
            view = MultiprocessingView(processes=self.app.pargs.cores)
        else:
            view = SequentialView()

        design.debug = self.app.pargs.test

        results = design(product=product,
                         hosts=_hosts,
                         view=view,
                         aerobic=not self.app.pargs.anaerobic)

        results['heterologous_pathway'] = results.heterologous_pathway.apply(
            str)
        results['manipulations'] = results.manipulations.apply(str)

        OUTPUT_WRITER[output_format](results, output)
Exemplo n.º 18
0
 def setUp(self):
     self.view = MultiprocessingView()