Example #1
0
    def get_gg(self, mf):
        from mocdp.comp.composite import CompositeNamedDP
        from mocdp.ndp.named_coproduct import NamedDPCoproduct
        from mocdp.comp.composite_templatize import cndp_templatize_children
        from mocdp.comp.composite_templatize import ndpcoproduct_templatize
        from mcdp_report.gg_ndp import gvgen_from_ndp

        ndp = mf.get_ndp()
        
        if isinstance(ndp, CompositeNamedDP):
            ndp2 = cndp_templatize_children(ndp)
            # print('setting _hack_force_enclose %r' % enclosed)
            if self.enclosed:
                setattr(ndp2, '_hack_force_enclose', True)
        elif isinstance(ndp, NamedDPCoproduct):
            ndp2 = ndpcoproduct_templatize(ndp)
        else:
            ndp2 = ndp
    
        library = mf.get_library()
        images_paths = library.get_images_paths() if library is not None else []
        
        # we actually don't want the name on top
        yourname = None  # name
        gg = gvgen_from_ndp(ndp2, style=self.style, direction=self.direction,
                            images_paths=images_paths, yourname=yourname,
                            skip_initial=self.skip_initial)
    
        return gg
Example #2
0
    def get_gg(self, mf):
        from mcdp_report.gg_ndp import gvgen_from_ndp

        template = mf.get_template()
        library = mf.get_library()
        yourname = mf.get_yourname()

        if library is not None:
            context = library._generate_context_with_hooks()
        else:
            from mocdp.comp.context import Context
            context = Context()

        ndp = template.get_template_with_holes(context)

        if self.templatize_children:
            from mcdp_figures.figures_ndp import templatize_children_for_figures
            ndp = templatize_children_for_figures(ndp, enclosed=self.enclosed)

        if self.enclosed:
            setattr(ndp, '_hack_force_enclose', True)

        images_paths = library.get_images_paths()
        image_source = ImagesFromPaths(images_paths)
        gg = gvgen_from_ndp(ndp,
                            style=self.style,
                            direction=self.direction,
                            image_source=image_source,
                            yourname=yourname,
                            skip_initial=True)

        return gg
Example #3
0
def plot_different_solutions(libname, ndpname, query, out, upper=None):
    if not os.path.exists(out):
        os.makedirs(out)
    library = get_test_library(libname)
    #library.use_cache_dir(os.path.join(out, 'cache'))
    context = Context()
    ndp = library.load_ndp(ndpname, context)

    context = library._generate_context_with_hooks()
    ndp_labelled = get_labelled_version(ndp)
    dp0 = ndp_labelled.get_dp()
    if upper is not None:
        _, dpU = get_dp_bounds(dp0, nl=1, nu=upper)
        dp = dpU
    else:
        dp = dp0

    M = dp.get_imp_space()

    with open(os.path.join(out, 'ndp.txt'), 'w') as f:
        f.write(ndp.repr_long())
    with open(os.path.join(out, 'M.txt'), 'w') as f:
        f.write(M.repr_long())
    with open(os.path.join(out, 'dp.txt'), 'w') as f:
        f.write(dp.repr_long())
    with open(os.path.join(out, 'dp0.txt'), 'w') as f:
        f.write(dp0.repr_long())

    f = convert_string_query(ndp=ndp, query=query, context=context)

    report = Report()

    res = dp.solve(f)
    print('num solutions: %s' % len(res.minimals))
    for ri, r in enumerate(res.minimals):
        ms = dp.get_implementations_f_r(f, r)

        for j, m in enumerate(ms):
            imp_dict = get_imp_as_recursive_dict(M, m)
            print imp_dict

            images_paths = library.get_images_paths()
            gv = GetValues(ndp=ndp, imp_dict=imp_dict, nu=upper, nl=1)

            gg = gvgen_from_ndp(ndp=ndp, style=STYLE_GREENREDSYM,
                                images_paths=images_paths,
                                plotting_info=gv)

            with report.subsection('%s-%s' % (ri, j)) as rr:
                gg_figure(rr, 'figure', gg, do_png=True, do_pdf=False,
                          do_svg=False, do_dot=False)


    fn = os.path.join(out, 'solutions.html')
    print('writing to %s' % fn)
    report.to_html(fn)
Example #4
0
 def get_gg(self, mf):
     """ This expands the children, forces the enclosure """
     library = mf.get_library()
     images_paths = library.get_images_paths() if library is not None else []
     ndp = mf.get_ndp()
     yourname = None  # name
     from mcdp_report.gg_ndp import gvgen_from_ndp
     gg = gvgen_from_ndp(ndp, style=self.style, direction=self.direction,
                         images_paths=images_paths, yourname=yourname,
                         skip_initial=True)
     return gg
Example #5
0
def plot_ndp(r, name, ndp, library):

    ndp = cndp_templatize_children(ndp)

    images_paths = library.get_images_paths()

    setattr(ndp, '_hack_force_enclose', True)
    gg = gvgen_from_ndp(ndp,
                        style=STYLE_GREENREDSYM,
                        images_paths=images_paths)
    gg_figure(r, name, gg, do_pdf=False, do_svg=False, do_dot=False)
Example #6
0
def test_imp_dict_1(id_ndp, ndp):
    if '_inf' in id_ndp:  # infinite
        return

    try:
        ndp.check_fully_connected()
    except NotConnected:
        print('Skipping test_imp_dict_1 because %r not connected.' % id_ndp)
        return

    ndp_labeled = get_labelled_version(ndp)

    dp0 = ndp_labeled.get_dp()
    F = dp0.get_fun_space()
    I = dp0.get_imp_space()
    # print ndp_labeled.repr_long()
    # print dp0.repr_long()
    print('I: %s' % I.repr_long())
    

    f = list(F.get_minimal_elements())[0]
    try:
        ur = dp0.solve(f)
    except NotSolvableNeedsApprox:
        return

    imp_dict = None
    for r in ur.minimals:
        imps = dp0.get_implementations_f_r(f, r)
        for imp in imps:
            I.belongs(imp)
            context = {}
            imp_dict = get_imp_as_recursive_dict(I, imp)
            print('imp_dict: {}'.format(imp_dict))
            artifact = ndp_make(ndp, imp_dict, context)
            print('artifact: {}'.format(artifact))
            
    # Let's just do it with one
    if imp_dict is not None:

        gv = GetValues(ndp=ndp, imp_dict=imp_dict, nu=None, nl=None)

        images_paths = []  # library.get_images_paths()
        from mcdp_report.gdc import STYLE_GREENREDSYM
        gg = gvgen_from_ndp(ndp=ndp, style=STYLE_GREENREDSYM, images_paths=images_paths,
                            plotting_info=gv)

        from reprep import Report
        from mcdp_report.gg_utils import gg_figure
        report = Report()
        gg_figure(report, 'figure', gg, do_png=True, do_pdf=False, do_svg=False, do_dot=False)
        fn = os.path.join('out', 'test_imp_dict_1', '%s.html' % id_ndp)
        print('written to %s' % fn)
        report.to_html(fn)
Example #7
0
def test_imp_dict_1(id_ndp, ndp):
    if '_inf' in id_ndp:  # infinite
        return

    try:
        ndp.check_fully_connected()
    except NotConnected:
        print('Skipping test_imp_dict_1 because %r not connected.' % id_ndp)
        return

    ndp_labeled = get_labelled_version(ndp)

    dp0 = ndp_labeled.get_dp()
    F = dp0.get_fun_space()
    I = dp0.get_imp_space()
    # print ndp_labeled.repr_long()
    # print dp0.repr_long()
    print('I: %s' % I.repr_long())
    

    f = list(F.get_minimal_elements())[0]
    try:
        ur = dp0.solve(f)
    except NotSolvableNeedsApprox:
        return

    imp_dict = None
    for r in ur.minimals:
        imps = dp0.get_implementations_f_r(f, r)
        for imp in imps:
            I.belongs(imp)
            context = {}
            imp_dict = get_imp_as_recursive_dict(I, imp)
            print('imp_dict: {}'.format(imp_dict))
            artifact = ndp_make(ndp, imp_dict, context)
            print('artifact: {}'.format(artifact))
            
    # Let's just do it with one
    if imp_dict is not None:

        gv = GetValues(ndp=ndp, imp_dict=imp_dict, nu=None, nl=None)

#         images_paths = []  # library.get_images_paths()
        from mcdp_report.gdc import STYLE_GREENREDSYM
        gg = gvgen_from_ndp(ndp=ndp, style=STYLE_GREENREDSYM,
                            plotting_info=gv)

        from reprep import Report
        from mcdp_report.gg_utils import gg_figure
        report = Report()
        gg_figure(report, 'figure', gg, do_png=True, do_pdf=False, do_svg=False, do_dot=False)
        fn = os.path.join('out', 'test_imp_dict_1', '%s.html' % id_ndp)
        print('written to %s' % fn)
        report.to_html(fn)
Example #8
0
    def get_gg(self, mf):
        ndp = mf.get_ndp()
        library =mf.get_library()
        yourname = mf.get_yourname()
        
        images_paths =  library.get_images_paths() if library else []
        from mcdp_report.gg_ndp import gvgen_from_ndp

        gg = gvgen_from_ndp(ndp, self. style, images_paths=images_paths,
                            yourname=yourname, direction=self.direction,
                            skip_initial=True)
        return gg
Example #9
0
 def get_gg(self, mf):
     """ This expands the children, forces the enclosure """
     image_source = mf.get_image_source()
     ndp = mf.get_ndp()
     yourname = None  # name
     gg = gvgen_from_ndp(ndp,
                         style=self.style,
                         direction=self.direction,
                         image_source=image_source,
                         yourname=yourname,
                         skip_initial=True)
     return gg
Example #10
0
    def get_gg(self, mf):
        ndp = mf.get_ndp()
        image_source = mf.get_image_source()
        yourname = mf.get_yourname()

        gg = gvgen_from_ndp(ndp=ndp,
                            style=self.style,
                            image_source=image_source,
                            yourname=yourname,
                            direction=self.direction,
                            skip_initial=True)
        return gg
Example #11
0
def ndp_template_graph_enclosed(library, template, style, yourname, data_format, direction, enclosed):
    assert isinstance(template, TemplateForNamedDP)
    mcdp_dev_warning('Wrong - need assume ndp const')

    context = library._generate_context_with_hooks()

    ndp = template.get_template_with_holes(context)

    if enclosed:
        setattr(ndp, '_hack_force_enclose', True)

    images_paths = library.get_images_paths()
    gg = gvgen_from_ndp(ndp, style=style, direction=direction,
                        images_paths=images_paths, yourname=yourname)
    return gg_get_format(gg, data_format)
Example #12
0
    def get_gg(self, mf):

        ndp = mf.get_ndp()

        ndp2 = templatize_children_for_figures(ndp, enclosed=self.enclosed)

        image_source = mf.get_image_source()
        # we actually don't want the name on top
        yourname = None  # name

        gg = gvgen_from_ndp(ndp2,
                            style=self.style,
                            direction=self.direction,
                            image_source=image_source,
                            yourname=yourname,
                            skip_initial=self.skip_initial)

        return gg
Example #13
0
    def get_gg(self, mf):
        ndp = mf.get_ndp()
        library =mf.get_library()
        
        yourname = None 
        if self.labeled:
            if hasattr(ndp, ATTR_LOAD_NAME):
                yourname = getattr(ndp, ATTR_LOAD_NAME)

        from mocdp.comp.composite_templatize import ndp_templatize
        ndp = ndp_templatize(ndp, mark_as_template=False)
        
        images_paths = library.get_images_paths() if library else []
    
        from mcdp_report.gg_ndp import gvgen_from_ndp
        gg = gvgen_from_ndp(ndp, self.style, yourname=yourname,
                            images_paths=images_paths, direction=self.direction,
                            skip_initial=True)
        return gg
Example #14
0
    def get_gg(self, mf):
        ndp = mf.get_ndp()
        image_source = mf.get_image_source()

        yourname = None
        if self.labeled:
            if hasattr(ndp, MCDPConstants.ATTR_LOAD_NAME):
                yourname = getattr(ndp, MCDPConstants.ATTR_LOAD_NAME)

        from mocdp.comp.composite_templatize import ndp_templatize
        ndp = ndp_templatize(ndp, mark_as_template=False)

        gg = gvgen_from_ndp(ndp=ndp,
                            style=self.style,
                            yourname=yourname,
                            image_source=image_source,
                            direction=self.direction,
                            skip_initial=True)
        return gg
Example #15
0
File: image.py Project: rusi/mcdp
def ndp_template_graph_enclosed(library, template, style, yourname,
                                data_format, direction, enclosed,
                                image_source):
    assert isinstance(template, TemplateForNamedDP)
    mcdp_dev_warning('Wrong - need assume ndp const')

    context = library._generate_context_with_hooks()

    ndp = template.get_template_with_holes(context)

    if enclosed:
        setattr(ndp, '_hack_force_enclose', True)

    gg = gvgen_from_ndp(ndp,
                        style=style,
                        direction=direction,
                        image_source=image_source,
                        yourname=yourname)
    return gg_get_format(gg, data_format)
Example #16
0
    def get_gg(self, mf):
        from mcdp_report.gg_ndp import gvgen_from_ndp

        template = mf.get_template()
        library = mf.get_library()
        yourname = mf.get_yourname()
        
        if library is not None:
            context = library._generate_context_with_hooks()
        else:
            from mocdp.comp.context import Context
            context = Context()
    
        ndp = template.get_template_with_holes(context)
    
        if self.enclosed:
            setattr(ndp, '_hack_force_enclose', True)
    
        images_paths = library.get_images_paths()
        gg = gvgen_from_ndp(ndp, style=self.style, direction=self.direction,
                            images_paths=images_paths, yourname=yourname,
                            skip_initial=True)
    
        return gg
Example #17
0
File: test1.py Project: rusi/mcdp
def plot_different_solutions(libname, ndpname, query, out, upper=None):
    if not os.path.exists(out):
        os.makedirs(out)
    library = get_test_library(libname)
    #library.use_cache_dir(os.path.join(out, 'cache'))
    context = Context()
    ndp = library.load_ndp(ndpname, context)

    context = library._generate_context_with_hooks()
    ndp_labelled = get_labelled_version(ndp)
    dp0 = ndp_labelled.get_dp()
    if upper is not None:
        _, dpU = get_dp_bounds(dp0, nl=1, nu=upper)
        dp = dpU
    else:
        dp = dp0

    M = dp.get_imp_space()

    with open(os.path.join(out, 'ndp.txt'), 'w') as f:
        f.write(ndp.repr_long())
    with open(os.path.join(out, 'M.txt'), 'w') as f:
        f.write(M.repr_long())
    with open(os.path.join(out, 'dp.txt'), 'w') as f:
        f.write(dp.repr_long())
    with open(os.path.join(out, 'dp0.txt'), 'w') as f:
        f.write(dp0.repr_long())

    f = convert_string_query(ndp=ndp, query=query, context=context)

    report = Report()

    res = dp.solve(f)
    print('num solutions: %s' % len(res.minimals))
    for ri, r in enumerate(res.minimals):
        ms = dp.get_implementations_f_r(f, r)

        for j, m in enumerate(ms):
            imp_dict = get_imp_as_recursive_dict(M, m)
            logger.info(imp_dict)

            images_paths = library.get_images_paths()
            image_source = ImagesFromPaths(images_paths)
            gv = GetValues(ndp=ndp, imp_dict=imp_dict, nu=upper, nl=1)

            gg = gvgen_from_ndp(ndp=ndp,
                                style=STYLE_GREENREDSYM,
                                image_source=image_source,
                                plotting_info=gv)

            with report.subsection('%s-%s' % (ri, j)) as rr:
                gg_figure(rr,
                          'figure',
                          gg,
                          do_png=True,
                          do_pdf=False,
                          do_svg=False,
                          do_dot=False)

    fn = os.path.join(out, 'solutions.html')
    print('writing to %s' % fn)
    report.to_html(fn)
Example #18
0
def solve_main(
    logger,
    config_dirs,
    maindir,
    cache_dir,
    model_name,
    lower,
    upper,
    out_dir,
    max_steps,
    query_strings,
    intervals,
    _exp_advanced,
    expect_nres,
    imp,
    expect_nimp,
    plot,
    do_movie,
    # expect_res=None,
    expect_res,  # @UnusedVariable
    make,
):

    if out_dir is None:
        out = solve_get_output_dir(prefix="out/out")
    else:
        out = out_dir

    logger.info("Using output dir %r" % out)

    librarian = Librarian()
    logger.info("Looking for libraries in %s..." % config_dirs)
    for e in config_dirs:
        librarian.find_libraries(e)
    logger.info("Found %d libraries." % len(librarian.get_libraries()))

    library = librarian.get_library_by_dir(maindir)
    if cache_dir is not None:
        library.use_cache_dir(cache_dir)

    ndp = library.load_ndp(model_name)
    basename = model_name

    if make or (plot and imp):
        ndp_labelled = get_labelled_version(ndp)
    else:
        ndp_labelled = ndp

    basename, dp = solve_get_dp_from_ndp(basename=basename, ndp=ndp_labelled, lower=lower, upper=upper)

    F = dp.get_fun_space()
    R = dp.get_res_space()
    UR = UpperSets(R)

    query = " ".join(query_strings)
    c = library.parse_constant(query)
    tu = get_types_universe()
    try:
        tu.check_leq(c.unit, F)
    except NotLeq as e:
        msg = "The value given cannot be converted to functionality space."
        raise_wrapped(UserError, e, msg, unit=c.unit, F=F, compact=True)
    fg = express_value_in_isomorphic_space(c.unit, c.value, F)

    logger.info("query: %s" % F.format(fg))

    tracer = Tracer(logger=logger)
    res, trace = solve_meat_solve(tracer, ndp, dp, fg, intervals, max_steps, _exp_advanced)

    nres = len(res.minimals)

    if expect_nres is not None:
        if nres != expect_nres:
            msg = "Found wrong number of resources"
            raise_desc(ExpectationsNotMet, msg, expect_nres=expect_nres, nres=nres)

    if imp:
        M = dp.get_imp_space()
        nimplementations = 0
        for r in res.minimals:
            ms = dp.get_implementations_f_r(fg, r)
            nimplementations += len(ms)
            s = "r = %s " % R.format(r)
            for j, m in enumerate(ms):
                # print('m = %s' % str(m))
                s += "\n  implementation %d of %d: m = %s " % (j + 1, len(ms), M.format(m))

                if make:
                    imp_dict = get_imp_as_recursive_dict(M, m)  # , ignore_hidden=False)
                    print("imp dict: %r" % imp_dict)
                    context = {}
                    artifact = ndp_make(ndp, imp_dict, context)

                    print("artifact: %s" % artifact)

            tracer.log(s)

        if expect_nimp is not None:
            if expect_nimp != nimplementations:
                msg = "Found wrong number of implementations"
                raise_desc(ExpectationsNotMet, msg, expect_nimp=expect_nimp, nimplementations=nimplementations)

    #     if expect_res is not None:
    #         value = interpret_string(expect_res)
    #         tracer.log('value: %s' % value)
    #         res_expected = value.value
    #         tu = get_types_universe()
    #         # If it's a tuple of two elements, then we assume it's upper/lower bounds
    #         if isinstance(value.unit, PosetProduct):
    #             subs = value.unit.subs
    #             assert len(subs) == 2, subs
    #
    #             lower_UR_expected, upper_UR_expected = subs
    #             lower_res_expected, upper_res_expected = value.value
    #
    #             lower_bound = tu.get_embedding(lower_UR_expected, UR)[0](lower_res_expected)
    #             upper_bound = tu.get_embedding(upper_UR_expected, UR)[0](upper_res_expected)
    #
    #             tracer.log('lower: %s <= %s' % (UR.format(lower_bound), UR.format(res)))
    #             tracer.log('upper: %s <= %s' % (UR.format(upper_bound), UR.format(res)))
    #
    #             UR.check_leq(lower_bound, res)
    #             UR.check_leq(res, upper_bound)
    #         else:
    #             # only one element: equality
    #             UR_expected = value.unit
    #             tu.check_leq(UR_expected, UR)
    #             A_to_B, _B_to_A = tu.get_embedding(UR_expected, UR)
    #
    #             res_expected_f = A_to_B(res_expected)
    #             try:
    #                 UR.check_equal(res, res_expected_f)
    #             except NotEqual as e:
    #                 raise_wrapped(ExpectationsNotMet, e, 'res is different',
    #                               res=res, res_expected=res_expected, compact=True)

    if plot:
        r = Report()
        if _exp_advanced:
            from mcdp_report.generic_report_utils import generic_report

            generic_report(r, dp, trace, annotation=None, axis0=(0, 0, 0, 0))
        else:
            f = r.figure()
            from mcdp_report.generic_report_utils import generic_plot

            generic_plot(f, space=UR, value=res)
            from mcdp_report.generic_report_utils import generic_report_trace

            generic_report_trace(r, ndp, dp, trace, out, do_movie=do_movie)

        out_html = os.path.join(out, "report.html")
        logger.info("writing to %r" % out_html)
        r.to_html(out_html)

    if plot and imp:
        from mcdp_report_ndp_tests.test1 import GetValues
        from mcdp_report.gg_ndp import gvgen_from_ndp
        from mcdp_report.gdc import STYLE_GREENREDSYM
        from mcdp_report.gg_utils import gg_figure

        M = dp.get_imp_space()

        report_solutions = Report()
        for i, r in enumerate(res.minimals):
            ms = dp.get_implementations_f_r(fg, r)
            for j, m in enumerate(ms):

                imp_dict = get_imp_as_recursive_dict(M, m)
                images_paths = library.get_images_paths()
                gv = GetValues(ndp=ndp, imp_dict=imp_dict, nu=upper, nl=1)

                setattr(ndp, "_hack_force_enclose", True)

                with report_solutions.subsection("sol-%s-%s" % (i, j)) as rr:
                    # Left right
                    gg = gvgen_from_ndp(
                        ndp=ndp, style=STYLE_GREENREDSYM, images_paths=images_paths, plotting_info=gv, direction="LR"
                    )

                    gg_figure(rr, "figure", gg, do_png=True, do_pdf=True, do_svg=False, do_dot=False)

                    # Top-bottom
                    gg = gvgen_from_ndp(
                        ndp=ndp, style=STYLE_GREENREDSYM, images_paths=images_paths, plotting_info=gv, direction="TB"
                    )

                    gg_figure(rr, "figure2", gg, do_png=True, do_pdf=True, do_svg=False, do_dot=False)

        out_html = os.path.join(out, "report_solutions.html")
        logger.info("writing to %r" % out_html)
        report_solutions.to_html(out_html)
Example #19
0
File: test0.py Project: rusi/mcdp
 def graph_default(_, ndp):
     _gg = gvgen_from_ndp(ndp, style='default')
Example #20
0
def solve_main(
        logger,
        config_dirs,
        maindir,
        cache_dir,
        model_name,
        lower,
        upper,
        out_dir,
        max_steps,
        query_strings,
        intervals,
        _exp_advanced,
        expect_nres,
        imp,
        expect_nimp,
        plot,
        do_movie,

        # expect_res=None,
        expect_res,  # @UnusedVariable
        make):

    if out_dir is None:
        out = solve_get_output_dir(prefix='out/out')
    else:
        out = out_dir

    logger.info('Using output dir %r' % out)

    librarian = Librarian()
    logger.info('Looking for libraries in %s...' % config_dirs)
    for e in config_dirs:
        librarian.find_libraries(e)
    logger.info('Found %d libraries.' % len(librarian.get_libraries()))

    library = librarian.get_library_by_dir(maindir)
    if cache_dir is not None:
        library.use_cache_dir(cache_dir)

    ndp = library.load_ndp(model_name)
    basename = model_name

    if make or (plot and imp):
        ndp_labelled = get_labelled_version(ndp)
    else:
        ndp_labelled = ndp

    basename, dp = solve_get_dp_from_ndp(basename=basename,
                                         ndp=ndp_labelled,
                                         lower=lower,
                                         upper=upper)

    F = dp.get_fun_space()
    R = dp.get_res_space()
    UR = UpperSets(R)

    query = " ".join(query_strings)
    c = library.parse_constant(query)
    tu = get_types_universe()
    try:
        tu.check_leq(c.unit, F)
    except NotLeq as e:
        msg = 'The value given cannot be converted to functionality space.'
        raise_wrapped(UserError, e, msg, unit=c.unit, F=F, compact=True)
    fg = express_value_in_isomorphic_space(c.unit, c.value, F)

    logger.info('query: %s' % F.format(fg))

    tracer = Tracer(logger=logger)
    res, trace = solve_meat_solve_ftor(tracer, ndp, dp, fg, intervals,
                                       max_steps, _exp_advanced)

    nres = len(res.minimals)

    if expect_nres is not None:
        if nres != expect_nres:
            msg = 'Found wrong number of resources'
            raise_desc(ExpectationsNotMet,
                       msg,
                       expect_nres=expect_nres,
                       nres=nres)

    if imp:
        M = dp.get_imp_space()
        nimplementations = 0
        for r in res.minimals:
            ms = dp.get_implementations_f_r(fg, r)
            nimplementations += len(ms)
            s = 'r = %s ' % R.format(r)
            for j, m in enumerate(ms):
                # print('m = %s' % str(m))
                s += "\n  implementation %d of %d: m = %s " % (j + 1, len(ms),
                                                               M.format(m))

                if make:
                    imp_dict = get_imp_as_recursive_dict(
                        M, m)  # , ignore_hidden=False)
                    print('imp dict: %r' % imp_dict)
                    context = {}
                    artifact = ndp_make(ndp, imp_dict, context)

                    print('artifact: %s' % artifact)

            tracer.log(s)

        if expect_nimp is not None:
            if expect_nimp != nimplementations:
                msg = 'Found wrong number of implementations'
                raise_desc(ExpectationsNotMet,
                           msg,
                           expect_nimp=expect_nimp,
                           nimplementations=nimplementations)


#     if expect_res is not None:
#         value = interpret_string(expect_res)
#         tracer.log('value: %s' % value)
#         res_expected = value.value
#         tu = get_types_universe()
#         # If it's a tuple of two elements, then we assume it's upper/lower bounds
#         if isinstance(value.unit, PosetProduct):
#             subs = value.unit.subs
#             assert len(subs) == 2, subs
#
#             lower_UR_expected, upper_UR_expected = subs
#             lower_res_expected, upper_res_expected = value.value
#
#             lower_bound = tu.get_embedding(lower_UR_expected, UR)[0](lower_res_expected)
#             upper_bound = tu.get_embedding(upper_UR_expected, UR)[0](upper_res_expected)
#
#             tracer.log('lower: %s <= %s' % (UR.format(lower_bound), UR.format(res)))
#             tracer.log('upper: %s <= %s' % (UR.format(upper_bound), UR.format(res)))
#
#             UR.check_leq(lower_bound, res)
#             UR.check_leq(res, upper_bound)
#         else:
#             # only one element: equality
#             UR_expected = value.unit
#             tu.check_leq(UR_expected, UR)
#             A_to_B, _B_to_A = tu.get_embedding(UR_expected, UR)
#
#             res_expected_f = A_to_B(res_expected)
#             try:
#                 UR.check_equal(res, res_expected_f)
#             except NotEqual as e:
#                 raise_wrapped(ExpectationsNotMet, e, 'res is different',
#                               res=res, res_expected=res_expected, compact=True)

    if plot:
        r = Report()
        if _exp_advanced:
            from mcdp_report.generic_report_utils import generic_report
            generic_report(r, dp, trace, annotation=None, axis0=(0, 0, 0, 0))
        else:
            f = r.figure()
            from mcdp_report.generic_report_utils import generic_plot
            generic_plot(f, space=UR, value=res)
            from mcdp_report.generic_report_utils import generic_report_trace
            generic_report_trace(r, ndp, dp, trace, out, do_movie=do_movie)

        out_html = os.path.join(out, 'report.html')
        logger.info('writing to %r' % out_html)
        r.to_html(out_html)

    if plot and imp:
        from mcdp_report_ndp_tests.test1 import GetValues
        from mcdp_report.gg_ndp import gvgen_from_ndp
        from mcdp_report.gdc import STYLE_GREENREDSYM
        from mcdp_report.gg_utils import gg_figure
        M = dp.get_imp_space()

        report_solutions = Report()
        for i, r in enumerate(res.minimals):
            ms = dp.get_implementations_f_r(fg, r)
            for j, m in enumerate(ms):

                imp_dict = get_imp_as_recursive_dict(M, m)
                images_paths = library.get_images_paths()
                image_source = ImagesFromPaths(images_paths)
                gv = GetValues(ndp=ndp, imp_dict=imp_dict, nu=upper, nl=1)

                setattr(ndp, '_hack_force_enclose', True)

                with report_solutions.subsection('sol-%s-%s' % (i, j)) as rr:
                    # Left right
                    gg = gvgen_from_ndp(ndp=ndp,
                                        style=STYLE_GREENREDSYM,
                                        image_source=image_source,
                                        plotting_info=gv,
                                        direction='LR')

                    gg_figure(rr,
                              'figure',
                              gg,
                              do_png=True,
                              do_pdf=True,
                              do_svg=False,
                              do_dot=False)

                    # Top-bottom
                    gg = gvgen_from_ndp(ndp=ndp,
                                        style=STYLE_GREENREDSYM,
                                        image_source=image_source,
                                        plotting_info=gv,
                                        direction='TB')

                    gg_figure(rr,
                              'figure2',
                              gg,
                              do_png=True,
                              do_pdf=True,
                              do_svg=False,
                              do_dot=False)

        out_html = os.path.join(out, 'report_solutions.html')
        logger.info('writing to %r' % out_html)
        report_solutions.to_html(out_html)
Example #21
0
File: test0.py Project: rusi/mcdp
 def graph_clean(_, ndp):
     _gg = gvgen_from_ndp(ndp, style='clean')
Example #22
0
File: test0.py Project: rusi/mcdp
 def graph_greenredsym(_, ndp):
     _gg = gvgen_from_ndp(ndp, style='greenredsym')
Example #23
0
def graph_greenredsym(_, ndp):
    _gg = gvgen_from_ndp(ndp, style='greenredsym')
Example #24
0
def graph_clean(_, ndp):
    _gg = gvgen_from_ndp(ndp, style='clean')
Example #25
0
def graph_default(_, ndp):
    _gg = gvgen_from_ndp(ndp, style='default')