Пример #1
0
    def test_problems(self):

        folder = os.path.join(get_pymoo(), "pymoo", "usage", "problems")
        files = [os.path.join(folder, fname) for fname in os.listdir(folder)]

        files.append(
            os.path.join(get_pymoo(), "pymoo", "usage", "usage_problem.py"))

        test_usage(files)
Пример #2
0
def update_and_run_notebook(filename, replace=True, execute=False):
    nb = load_notebook(filename)

    if replace:

        # Loop through all cells
        for k in range(len(nb['cells'])):
            # If cell is code and has usage metadata set, update the .ipynb json
            if nb['cells'][k]['cell_type'] == 'code':

                code = nb['cells'][k]['metadata'].get('code')
                section = nb['cells'][k]['metadata'].get('section')

                if code:
                    code = get_usage(code)

                    if section:
                        code = get_section(code, section)

                    nb['cells'][k]['source'] = code

        # remove trailing empty cells
        while len(nb["cells"]) > 0 and nb["cells"][-1]['cell_type'] == 'code' and len(nb["cells"][-1]['source']) == 0 \
                and nb["cells"][-1]['execution_count'] is None:
            nb["cells"] = nb["cells"][:-1]

    if execute:
        ep = ExecutePreprocessor(kernel_name='python3')
        ep.preprocess(nb, {'metadata': {'path': get_pymoo()}})

    with open(filename, 'wt') as f:
        nbformat.write(nb, f)
Пример #3
0
    def test(self):

        PYMOO_DIR = get_pymoo()
        DOC_DIR = os.path.join(PYMOO_DIR, "doc", "source")
        ipynb = []

        # collect all the jupyter ipynb in the documentation
        for root, directories, filenames in os.walk(DOC_DIR):
            for filename in filenames:
                if filename.endswith(
                        ".ipynb") and "checkpoint" not in filename:
                    ipynb.append(os.path.join(root, filename))

        ep = ExecutePreprocessor(timeout=10000, kernel_name='python3')

        for fname in ipynb:

            print(fname.split("/")[-1])

            import warnings
            warnings.filterwarnings("ignore")

            try:
                nb = nbformat.read(fname, nbformat.NO_CONVERT)
                ep.preprocess(nb, {'metadata': {'path': PYMOO_DIR}})

            except CellExecutionError:
                msg = 'Error executing the fname "%s".\n\n' % fname
                print(msg)
                raise
            finally:
                if OVERWRITE:
                    with open(fname, mode='wt') as f:
                        nbformat.write(nb, f)
Пример #4
0
    def test_values_of_indicators(self):
        l = [(GD, "gd"), (IGD, "igd")]
        folder = os.path.join(get_pymoo(), "tests", "performance_indicator")
        pf = np.loadtxt(os.path.join(folder, "performance_indicators.pf"))

        for indicator, ext in l:

            for i in range(1, 5):
                F = np.loadtxt(
                    os.path.join(folder, "performance_indicators_%s.f" % i))

                val = indicator(pf).calc(F)
                correct = np.loadtxt(
                    os.path.join(folder,
                                 "performance_indicators_%s.%s" % (i, ext)))
                self.assertTrue(correct == val)
Пример #5
0
 def test_usages(self):
     folder = os.path.join(get_pymoo(), "pymoo", "usage")
     test_usage([
         os.path.join(folder, fname)
         for fname in Path(folder).glob('**/*.py')
     ])
Пример #6
0
def get_pymoo_test():
    return os.path.join(get_pymoo(), "tests")
Пример #7
0
 def test_usages(self):
     folder = os.path.join(get_pymoo(), "pymoo", "usage", "visualization")
     test_usage([os.path.join(folder, fname) for fname in os.listdir(folder)])
Пример #8
0
 def setUpClass(cls):
     with open(
             os.path.join(get_pymoo(), "tests", "resources",
                          "cnsga2_run_zdt4.dat"), 'rb') as f:
         cls.data = pickle.load(f)
Пример #9
0
 def test_termination_criterion(self):
     folder = os.path.join(get_pymoo(), "pymoo", "usage", "termination")
     test_usage(
         [os.path.join(folder, fname) for fname in os.listdir(folder)])
Пример #10
0
import os

import numpy as np

from pymoo.configuration import get_pymoo
from pymoo.decision_making.high_tradeoff import HighTradeoffPoints
from pymoo.decision_making.high_tradeoff_inverted import HighTradeoffPointsInverted
from pymoo.visualization.scatter import Scatter

pf = np.loadtxt(
    os.path.join(get_pymoo(), "pymoo", "usage", "decision_making",
                 "knee-2d.out"))
dm = HighTradeoffPoints()

I = dm.do(pf)

plot = Scatter(angle=(0, 0))
plot.add(pf, alpha=0.2)
plot.add(pf[I], color="red", s=100)
plot.show()
Пример #11
0
 def test_decomposition(self):
     folder = os.path.join(get_pymoo(), "pymoo", "usage", "decomposition")
     test_usage(
         [os.path.join(folder, fname) for fname in os.listdir(folder)])
Пример #12
0
 def test_usages(self):
     test_usage([
         os.path.join(get_pymoo(), "pymoo", "usage",
                      "usage_performance_indicator.py")
     ])