コード例 #1
0
ファイル: dp_products.py プロジェクト: AndreaCensi/mcdp
 def __init__(self, nu):
     R = Rcomp()
     Fs = (R, R)
     self.nl = nu
     mcdp_dev_warning('This is not even true - it is the complicated function')
     amap = ProductNMap(Fs, R)
     WrapAMap.__init__(self, amap, None)
コード例 #2
0
ファイル: plotter_ur.py プロジェクト: AndreaCensi/mcdp
    def plot(self, pylab, axis, space, value, params={}):
        params0 = dict(color_shadow=[1.0, 0.8, 0.8], markers="k.", markers_params={})
        params0.update(params)

        color_shadow = params0.pop("color_shadow")
        markers = params0.pop("markers")
        markers_params = params0.pop("markers_params")
        if params0:
            raise ValueError(params0)

        self.axis = axis
        self.check_plot_space(space)

        minimals = [self._get_screen_coords(_, axis) for _ in value.minimals]
        print "minimals", minimals
        R2 = PosetProduct((Rcomp(), Rcomp()))
        v = R2.Us(minimals)

        from mcdp_report.generic_report_utils import extra_space_finite

        mcdp_dev_warning("incomplete PlotterUR")
        logger.error("todo: change this to plot a line")
        plot_upset_R2(
            pylab,
            v,
            axis,
            extra_space_shadow=extra_space_finite,
            color_shadow=color_shadow,
            markers=markers,
            marker_params=markers_params,
        )
コード例 #3
0
ファイル: multiset.py プロジェクト: AndreaCensi/mcdp
 def check_equal(self, a, b):
     m1 = a.get_elements()
     m2 = b.get_elements()
     mcdp_dev_warning('#XXX should use S.equal()')
     if not (m1 == m2):  # XXX: should use S.equal()...
         msg = "Not equal"
         raise_desc(NotEqual, msg, elements1=m1, elements2=m2)
コード例 #4
0
ファイル: drawing.py プロジェクト: AndreaCensi/mcdp
def plot_upset_R2(pylab, us, axis, color_shadow,
                  extra_space_shadow=0.05, color_lines='none', markers='r.',
                  marker_params={}):

    points = us.minimals

    xmin, xmax, ymin, ymax = axis
    for p in points:
        if xmin <= p[0] <= xmax and (ymin <= p[1] <= ymax):
            mcdp_dev_warning('This should be smarter')

            # draw a little of them
            if p[0] == xmax:
                axis = enlarge_x(axis, extra_space_shadow)
            if p[1] == ymax:
                axis = enlarge_y(axis, extra_space_shadow)

            plot_cone(pylab, p, axis, color_shadow=color_shadow,
                      color_lines=color_lines)
        else:
            logger.debug('Warning: point %s not in axis %s' % (p, axis))
            
    # cuteness
    if markers is not None:
        for p in points:
            # This is to avoid underflow
            # when using "finfo.tiny"
            eps = finfo.eps
            p = np.maximum(p, eps)
            #print('plot_upset_R2: marker params: %s ' % marker_params)
            pylab.plot(p[0], p[1], markers, clip_on=False, **marker_params)
コード例 #5
0
ファイル: product_map.py プロジェクト: AndreaCensi/mcdp
 def __init__(self, fs):
     fs = tuple(fs)
     self.fs = fs
     mcdp_dev_warning('add promotion to SpaceProduct')
     dom = PosetProduct(tuple(fi.get_domain() for fi in fs))
     cod = PosetProduct(tuple(fi.get_codomain() for fi in fs))
     Map.__init__(self, dom=dom, cod=cod)
コード例 #6
0
def eval_lfunction_invmult_ops(fs, context):
    if len(fs) == 1:
        return fs[0]
    elif len(fs) > 2: 
        mcdp_dev_warning('Maybe this should be smarter?')
        rest = eval_lfunction_invmult_ops(fs[1:], context)
        return eval_lfunction_invmult_ops([fs[0], rest], context) 
    else:   
        assert len(fs) == 2
        Fs = tuple(map(context.get_ftype, fs))
    
        if isinstance(Fs[0], Nat) and isinstance(Fs[1], Nat):
            dp = InvMult2Nat(Nat(), Fs)
        else:
            if isinstance(Fs[0], RcompUnits) and \
               isinstance(Fs[1], RcompUnits):
                R = mult_table(Fs[0], Fs[1])
                dp = InvMult2(R, Fs)
            elif isinstance(Fs[0], Rcomp) and isinstance(Fs[1], Rcomp):
                R = Rcomp()
                dp = InvMult2(R, Fs)
            else:
                msg = 'Could not create invplus for types {}.'.format(Fs)
                raise_desc(DPNotImplementedError, msg, Fs0=Fs[0], Fs1=Fs[1])
                
        return create_operation_lf(context, dp=dp, functions=fs,
                        name_prefix='_invmult', op_prefix='_ops',
                        res_prefix='_result') 
コード例 #7
0
ファイル: sequences_invplus.py プロジェクト: AndreaCensi/mcdp
def invmultU_solve_options(F, R, f, n, algo):
    """ Returns a set of points in R that are on the line r1*r2=f. """
    from .dp_inv_mult import InvMult2

    assert algo in [InvMult2.ALGO_UNIFORM, InvMult2.ALGO_VAN_DER_CORPUT]
    if is_top(F, f):
        mcdp_dev_warning('FIXME Need much more thought about this')
        top1 = R[0].get_top()
        top2 = R[1].get_top()
        s = set([(top1, top2)])
        return s

    check_isinstance(f, float)
            
    if f == 0.0:
        return set([(0.0, 0.0)])

    if algo == InvMult2.ALGO_UNIFORM:
        mcdp_dev_warning('TODO: add ALGO as parameter. ')
        ps = samplec(n, f)
    elif algo == InvMult2.ALGO_VAN_DER_CORPUT:
        x1, x2 = generate_exp_van_der_corput_sequence(n=n, C=f)
        ps = zip(x1, x2)
    else: # pragma: no cover
        assert False
    return ps
コード例 #8
0
def simplify_indices_F(F, coords):
    # Safety check: Clearly if it's not the identity it cannot be equal to ()
    R = get_R_from_F_coords(F, coords)
    if not (R == F):
        return coords

    # generic test
    i0 = get_id_indices(F)
    # compose
    i0coords = compose_indices(F, i0, coords, list)
    if i0 == i0coords:
        return ()

    if coords == [0] and len(F) == 1:
        return ()
    if coords == [0, 1] and len(F) == 2:
        return ()
    if coords == [0, (1,)] and len(F) == 2:
        return ()
    if coords == [0, 1, 2] and len(F) == 3:
        return ()

    mcdp_dev_warning('need a double check here')
    if coords == [[(0, 0)], [(1, 0)]]:
        return ()

    if coords == [[(0, 0)], [(1, 0), (1, 1)]]:
        return ()

    # [[(0, 1)], [(1, 0), (0, 0)]]
    return coords
コード例 #9
0
def eval_lfunction_invplus_ops(fs, context):
    if len(fs) == 1:
        raise DPInternalError(fs)
    elif len(fs) > 2: # pragma: no cover
        mcdp_dev_warning('Maybe this should be smarter?')    
        rest = eval_lfunction_invplus_ops(fs[1:], context)
        return eval_lfunction_invplus_ops([fs[0], rest], context) 
    else:   
        Fs = map(context.get_ftype, fs)
        R = Fs[0]
    
        if all(isinstance(_, RcompUnits) for _ in Fs):
            tu = get_types_universe()
            if not tu.leq(Fs[1], Fs[0]):
                msg = 'Inconsistent units %s and %s.' % (Fs[1], Fs[0])
                raise_desc(DPSemanticError, msg, Fs0=Fs[0], Fs1=Fs[1])
    
            if not tu.equal(Fs[1], Fs[0]):
                msg = 'This case was not implemented yet. Differing units %s and %s.' % (Fs[1], Fs[0])
                raise_desc(DPNotImplementedError, msg, Fs0=Fs[0], Fs1=Fs[1])
            
            dp = InvPlus2(R, tuple(Fs))            
        elif all(isinstance(_, Rcomp) for _ in Fs):
            dp = InvPlus2(R, tuple(Fs))
        elif all(isinstance(_, Nat) for _ in Fs):
            dp = InvPlus2Nat(R, tuple(Fs))
            
        else: # pragma: no cover
            msg = 'Cannot find operator for these types.'
            raise_desc(DPInternalError, msg, Fs=Fs)
        
        return create_operation_lf(context, dp=dp, functions=fs,
                               name_prefix='_invplus', op_prefix='_',
                                res_prefix='_result') 
コード例 #10
0
ファイル: dp_graph_flow_imp.py プロジェクト: AndreaCensi/mcdp
    def go_loop2(dp, imp):
        if do_imp:
            m0, _f2, _r2 = dp._unpack_m(imp)
        else:
            m0 = _f2 = _r2 = None

        (n1i, n1o) = go(dp.dp1, m0)

        i = gg.newItem('|')
        gg.propertyAppend(i, "shape", "plaintext")
        o = gg.newItem('|')
        gg.propertyAppend(o, "shape", "plaintext")

        l0 = gg.newLink(i, n1i, label=str(dp.dp1.get_fun_space()))
        l1 = gg.newLink(n1o, o, label=str(dp.dp1.get_res_space()))
        gg.propertyAppend(l0, 'arrowhead', 'none')
        gg.propertyAppend(l1, 'arrowhead', 'none')

        loop_label = str(dp.F2)

        mcdp_dev_warning('add option')
#         if False:
#             M = dp.get_imp_space_mod_res()
#             M0 = dp.dp1.get_imp_space_mod_res()
#             loop_label += ' M0: %s' % M0
#             loop_label += ' M: %s' % M
        l = gg.newLink(o, i, label=loop_label)
        gg.propertyAppend(l, "color", "red")
        gg.propertyAppend(l, "headport", "sw")
        gg.propertyAppend(l, "tailport", "s")
        
        gg.propertyAppend(l, 'arrowhead', 'none')

        return (i, o)
コード例 #11
0
ファイル: gg_utils.py プロジェクト: AndreaCensi/mcdp
def gg_deepcopy(ggraph):
    try:
        return deepcopy(ggraph)
    except Exception as e:
        print traceback.format_exc(e)
        mcdp_dev_warning('Deep copy of gvgen graph failed: happens when in IPython.')
        return ggraph
コード例 #12
0
ファイル: dp_series.py プロジェクト: AndreaCensi/mcdp
    def solve_trace(self, func, trace):
        if func in self._solve_cache:
            # trace.log('using cache for %s' % str(func))
            return trace.result(self._solve_cache[func])

        trace.values(type='series')

        with trace.child('dp1') as t:
            u1 = self.dp1.solve_trace(func, t)

        if do_extra_checks():
            R1 = self.dp1.get_res_space()
            tr1 = UpperSets(R1)
            tr1.belongs(u1)

        mcdp_dev_warning('rewrite this keeping structure')
        mins = set([])
        for u in u1.minimals:
            with trace.child('dp2') as t:
                v = self.dp2.solve_trace(u, t)
            mins.update(v.minimals)

        R = self.get_res_space()
        minimals = poset_minima(mins, R.leq)

        us = UpperSet(minimals, R)

        self._solve_cache[func] = us
        return trace.result(us)
コード例 #13
0
ファイル: html.py プロジェクト: AndreaCensi/mcdp
def get_language_css():
    from mcdp_library.utils.dir_from_package_nam import dir_from_package_name
    mcdp_dev_warning('TODO: remove from mcdp_web')
    package = dir_from_package_name('mcdp_web')
    fn = os.path.join(package, 'static', 'css', 'mcdp_language_highlight.css')
    with open(fn) as f:
        css = f.read()
    return css
コード例 #14
0
ファイル: dp_sum.py プロジェクト: AndreaCensi/mcdp
 def solve_r(self, r):
     if self.n > 2:
         msg = 'SumNRcompLDP:solve_r: Cannot invert more than two terms.'
         raise_desc(NotImplementedError, msg)
         
     mcdp_dev_warning('not sure')
     options = sample_sum_lowersets(self.R, self.F, r, self.nl)
     return self.F.Ls(options)
コード例 #15
0
def make_parallel_n(dps):
    if len(dps) == 2:
        return make_parallel(dps[0], dps[1])

    if len(dps) == 0:
        mcdp_dev_warning('This works but should be a special case.')

    return ParallelN(tuple(dps)) 
コード例 #16
0
ファイル: nat.py プロジェクト: AndreaCensi/mcdp
def RcompUnits_mult_lowersets_continuous(A, a, B, b, C):
    """ Multiplication on Rcompunits, extended for top, so that top*0 = Top """
    from mcdp_posets.poset import is_top
     
    if is_top(A, a) or is_top(B, b):
        return C.get_top()

    mcdp_dev_warning('catch overflow')
    return a * b
コード例 #17
0
ファイル: uppersets.py プロジェクト: AndreaCensi/mcdp
 def belongs(self, x):
     if not isinstance(x, LowerSet):
         msg = 'Not a lower set.'
         raise NotBelongs(msg)
     if not x.P == self.P:
         mcdp_dev_warning('should we try casting?')
         msg = 'Different poset: %s ≠ %s' % (self.P, x.P)
         raise_desc(NotBelongs, msg, self=self, x=x)
     return True
コード例 #18
0
    def get_top(self):
        if isinstance(self.S, FiniteCollectionAsSpace):
            res = FiniteCollection(elements=self.S.elements,
                                    S=self.S)
            if do_extra_checks():
                self.belongs(res)

            return res

        mcdp_dev_warning('Maybe should use a TooMuchComputation error.')
        msg = 'Cannot enumerate the elements of this space.'
        raise_desc(NotBounded, msg, space=self.S)
コード例 #19
0
ファイル: dp_coproduct.py プロジェクト: AndreaCensi/mcdp
    def solve_r(self, r):
        F = self.get_fun_space()

        s = []

        mcdp_dev_warning('use specific operation on antichains')
        for dp in self.dps:
            lf = dp.solve_r(r)
            s.extend(lf.maximals)

        res = F.Ls(poset_maxima(s, F.leq))

        return res
コード例 #20
0
ファイル: axis_algebra.py プロジェクト: AndreaCensi/mcdp
def enlarge(b, f):
    w = b[1] - b[0]
    h = b[3] - b[2]
    # print b, f, w, h
    
    dw = fix_underflow(f) * fix_underflow(w)
    dh = fix_underflow(h) * fix_underflow(f)
    a = (b[0] - dw, b[1] + dw, b[2] - dh, b[3] + dh)
    
    return a

    mcdp_dev_warning('this is not correct (axis might be negative)')
    return tuple(map(fix_underflow, a))
コード例 #21
0
ファイル: dp_coproduct.py プロジェクト: AndreaCensi/mcdp
    def solve(self, f):
        R = self.get_res_space()

        s = []

        mcdp_dev_warning('use specific operation on antichains')
        for dp in self.dps:
            rs = dp.solve(f)
            s.extend(rs.minimals)

        res = R.Us(poset_minima(s, R.leq))

        return res
コード例 #22
0
ファイル: context.py プロジェクト: AndreaCensi/mcdp
    def add_connection(self, c):
        self.info('Adding connection %r' % str(c))
        if not c.dp1 in self.names:
            raise_desc(DPSemanticError, 'Invalid connection: %r not found.' % c.dp1,
                       names=self.names, c=c)

        if not c.dp2 in self.names:
            raise_desc(DPSemanticError, 'Invalid connection: %r not found.' % c.dp2,
                       names=self.names, c=c)

        mcdp_dev_warning('redo this check')


        if self.is_new_function(c.dp2):
            msg = "Cannot add connection to new function %r." % c.dp2
            raise_desc(DPSemanticError, msg, c=c)

        if self.is_new_resource(c.dp1):
            msg = "Cannot add connection to new resource %r." % c.dp1
            raise_desc(DPSemanticError, msg, c=c)

        # Find if there is already a connection to c.dp2,c.s2
        # for c0 in self.connections:
        #    if c0.dp2 == c.dp2 and c0.s2 == c.s2:
        #        msg = 'There is already a connection to function %r of %r.' % (c.s2, c.dp2)
        #        raise_desc(DPSemanticError, msg)

        ndp1 = self.names[c.dp1]
        ndp2 = self.names[c.dp2]

        rnames = ndp1.get_rnames()
        if not c.s1 in rnames:
            msg = "Resource %r does not exist (known: %s)" % (c.s1, ", ".join(rnames))
            raise_desc(DPSemanticError, msg, known=rnames)

        fnames = ndp2.get_fnames()
        if not c.s2 in fnames:
            msg = "Function %r does not exist (known: %s)" % (c.s2, ", ".join(fnames))
            raise_desc(DPSemanticError, msg, known=fnames)


        R1 = ndp1.get_rtype(c.s1)
        F2 = ndp2.get_ftype(c.s2)
        # print('connecting R1 %s to R2 %s' % (R1, F2))
        if not (R1 == F2):
            msg = 'Connection between different spaces.'
            raise_desc(DPSemanticError, msg, c=c,
                       F2=F2, R1=R1, ndp1=ndp1,
                       ndp2=ndp2)

        self.connections.append(c)
コード例 #23
0
ファイル: images.py プロジェクト: AndreaCensi/mcdp
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)
コード例 #24
0
ファイル: test_md_rendering.py プロジェクト: AndreaCensi/mcdp
def define_tests_mcdp_web(context):
    """
        Looks for directories called *.mcdplib in the root of the package.
        
        It also looks for the files *.mcdp_tests.yaml inside.
    """
    for libname in enumerate_test_libraries():
        c2 = context.child(libname)

        c2.comp_dynamic(define_tests_rendering, libname)

        if False:
            c2.comp(test_mcdpweb_server, libname)
        else:
            mcdp_dev_warning('test_mcdpweb_server() is not enabled')
コード例 #25
0
ファイル: gdc.py プロジェクト: AndreaCensi/mcdp
    def should_I_skip_leq(self, context, c):
        from mcdp_report.gg_ndp import is_simple
        if self.policy_skip == 'never':
            return False
        elif self.policy_skip == 'if_second_simple':
            second_simple = is_simple(context.names[c.dp2])
            # first_simple = is_simple(context.names[c.dp1])
            # any_simple = second_simple or first_simple
            # both_simple = second_simple and first_simple

            mcdp_dev_warning('Add options here')
            skip = second_simple
            return skip
        else:
            assert False, self.policy_skip
コード例 #26
0
ファイル: parse_actions.py プロジェクト: AndreaCensi/mcdp
def add_where_information(where):
    """ Adds where field to DPSyntaxError or DPSemanticError thrown by code. """
    active = True
    if not active:
        logger.debug('Note: Error tracing disabled in add_where_information().')
        
    if not active:
        mcdp_dev_warning('add_where_information is disabled')
        yield
    else:
        try:
            yield
        except MCDPExceptionWithWhere as e:
            mcdp_dev_warning('add magic traceback handling here')
            _, _, tb = sys.exc_info()
            raise_with_info(e, where, tb)
コード例 #27
0
ファイル: eval_ndp_approx.py プロジェクト: AndreaCensi/mcdp
def eval_ndp_approx_lower(r, context):
    from mcdp_lang.eval_ndp_imp import eval_ndp
    from mcdp_dp.dp_transformations import get_dp_bounds

    nl = r.level
    ndp = eval_ndp(r.ndp, context)
    dp = ndp.get_dp()
    mcdp_dev_warning('make it better')
    dpl, _ = get_dp_bounds(dp, nl, 1)

    fnames = ndp.get_fnames()
    rnames = ndp.get_rnames()
    rnames = rnames if len(rnames) > 1 else rnames[0]
    fnames = fnames if len(fnames) > 1 else fnames[0]
    ndp2 = SimpleWrap(dpl, fnames, rnames)
    return ndp2
コード例 #28
0
ファイル: gg_utils.py プロジェクト: AndreaCensi/mcdp
def gg_get_formats(gg, data_formats):
    check_isinstance(data_formats, (list, tuple))
    res = []
    mcdp_dev_warning('TODO: optimize gg_get_formats')
    for data_format in data_formats:
        if not data_format in allowed_formats:
            msg = 'Invalid data format.' 
            raise_desc(ValueError, msg, data_formats=data_formats)

        if data_format == 'dot':
            d = get_dot_string(gg)
        else:
            d = gg_get_format(gg, data_format)

        res.append(d)
    return tuple(res)
コード例 #29
0
ファイル: gdc.py プロジェクト: AndreaCensi/mcdp
    def decorate_arrow_resource(self, l2):
        propertyAppend = self.gg.propertyAppend

        mcdp_dev_warning('this above has no effect')
        propertyAppend(l2, 'fontcolor', COLOR_DARKRED)

        if self.style == STYLE_GREENRED:
            propertyAppend(l2, 'color', COLOR_DARKRED)
            propertyAppend(l2, 'fontcolor', COLOR_DARKRED)
            propertyAppend(l2, 'arrowtail', 'inv')
            propertyAppend(l2, 'arrowhead', 'none')
            propertyAppend(l2, 'dir', 'both')

        if self.style == STYLE_GREENREDSYM:
            propertyAppend(l2, 'color', COLOR_DARKRED)
            propertyAppend(l2, 'arrowtail', 'dot')
            propertyAppend(l2, 'arrowhead', 'none')
            propertyAppend(l2, 'dir', 'both')
コード例 #30
0
ファイル: gdc.py プロジェクト: AndreaCensi/mcdp
    def decorate_arrow_function(self, l1):
        propertyAppend = self.gg.propertyAppend

        if self.style == STYLE_GREENRED:
            propertyAppend(l1, 'color', COLOR_DARKGREEN)
            propertyAppend(l1, 'arrowhead', 'normal')
            propertyAppend(l1, 'arrowtail', 'none')
            propertyAppend(l1, 'dir', 'both')

        if self.style == STYLE_GREENREDSYM:
            propertyAppend(l1, 'color', 'darkgreen')
            propertyAppend(l1, 'fontcolor', COLOR_DARKGREEN)
            propertyAppend(l1, 'arrowhead', 'dot')
            propertyAppend(l1, 'arrowtail', 'none')
            propertyAppend(l1, 'dir', 'both')

        mcdp_dev_warning('this above has no effect')
        propertyAppend(l1, 'fontcolor', COLOR_DARKGREEN)
コード例 #31
0
ファイル: tests.py プロジェクト: rusi/mcdp
def check_ex16b(context, _id_dp, dp):
    r = context.comp(check_ex16b_r, dp)
    context.add_report(r, 'ex16')


def check_ex16b_r(dp):
    funsp = dp.get_fun_space()
    bot = funsp.get_bottom()
    res = dp.solve(bot)
    print 'res', res
    r = Report()

    return r


mcdp_dev_warning('readd')


# @for_some_dps_dyn('ex16_loop')
def check_ex16c(context, _id_dp, dp):
    r = context.comp(check_ex16c_r, dp)
    context.add_report(r, 'ex16c')


def check_ex16c_r(dp):
    #     from mocdp.dp.dp_loop import SimpleLoop
    #     funsp = dp.get_fun_space()

    #     assert isinstance(dp, SimpleLoop)

    # Payload2ET