Example #1
0
def compute_model(variables_ordering=None, keep_single_enum=False):
    """
    Compute the read model and store its parts in global data structures.
    This function is a shortcut for calling all the steps of the model building
    that are not yet performed.
    If variables_ordering is not None, it is used as a file containing the
    order of variables used for encoding the model into BDDs.


    :param variables_ordering: the file containing a custom ordering
    :type variables_ordering: path to file
    :param keep_single_enum: whether or not enumerations with single values
                             should be converted into defines
    :type keep_single_enum: bool

    """
    if not nscompile.cmp_struct_get_read_model(global_compile_cmps()):
        raise NuSMVNoReadModelError("No read model.")

    # Check cmps and perform what is needed
    if not nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()):
        flatten_hierarchy(keep_single_enum=keep_single_enum)
    if not nscompile.cmp_struct_get_encode_variables(global_compile_cmps()):
        encode_variables(variables_ordering=variables_ordering)
    if not nscompile.cmp_struct_get_build_flat_model(global_compile_cmps()):
        build_flat_model()
    if not nscompile.cmp_struct_get_build_model(global_compile_cmps()):
        build_model()
Example #2
0
def flat_hierarchy():
    """
    Return the global flat hierarchy.

    :rtype: :class:`FlatHierarchy <pynusmv.node.FlatHierarchy>`
    """
    if not nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()):
        # Need a flat hierarchy
        raise NuSMVNeedFlatHierarchyError("Need flat hierarchy.")
    global __flat_hierarchy
    if __flat_hierarchy is None:
        __flat_hierarchy = FlatHierarchy(global_compile_flathierarchy())
    return __flat_hierarchy
Example #3
0
def prop_database():
    """
    Return the global properties database.

    :rtype: :class:`PropDb <pynusmv.prop.PropDb>`

    """
    if not nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()):
        # Need a flat hierarchy
        raise NuSMVNeedFlatHierarchyError("Need flat hierarchy.")
    global __prop_database
    if __prop_database is None:
        __prop_database = PropDb(nsprop.PropPkg_get_prop_database())
    return __prop_database
Example #4
0
def symb_table():
    """
    Return the main symbols table of the current model.

    :rtype: :class:`SymbTable <pynusmv.fsm.SymbTable>`

    """
    # Flatten hierarchy if needed
    global __symb_table
    if __symb_table is None:
        if nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()):
            __symb_table = SymbTable(nscompile.Compile_get_global_symb_table())
        else:
            flatten_hierarchy()
    return __symb_table
Example #5
0
def encode_variables(layers=None, variables_ordering=None):
    """
    Encode the BDD variables of the current model and store it in global data
    structures.
    If variables_ordering is provided, use this ordering to encode the
    variables; otherwise, the default ordering method is used.

    :param layers: the set of layers variables to encode
    :type layers: :class:`set`
    :param variables_ordering: the file containing a custom ordering
    :type variables_ordering: path to file

    :raise: a :exc:`NuSMVNeedFlatHierarchyError
            <pynusmv.exception.NuSMVNeedFlatHierarchyError>` if the model is
            not flattened
    :raise: a :exc:`NuSMVModelAlreadyEncodedError
            <pynusmv.exception.NuSMVModelAlreadyEncodedError>`
            if the variables are already encoded

    """
    # Check cmps
    if not nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()):
        raise NuSMVNeedFlatHierarchyError("Need flat hierarchy.")
    if nscompile.cmp_struct_get_encode_variables(global_compile_cmps()):
        raise NuSMVModelAlreadyEncodedError(
            "The variables are already encoded.")

    # See to understand why setting a default set value is not a good idea
    # http://pylint-messages.wikidot.com/messages:w0102
    layers = layers or {"model"}

    if variables_ordering is not None:
        nsopt.set_input_order_file(nsopt.OptsHandler_get_instance(),
                                   variables_ordering)

    encode_variables_for_layers(layers, init=True)

    # Update cmps
    nscompile.cmp_struct_set_encode_variables(global_compile_cmps())

    # Get global encoding
    global __bdd_encoding
    __bdd_encoding = BddEnc(nsenc.Enc_get_bdd_encoding())
Example #6
0
def flatten_hierarchy(keep_single_enum=False):
    """
    Flatten the read model and store it in global data structures.

    :param keep_single_enum: whether or not enumerations with single values
                             should be converted into defines
    :type keep_single_enum: bool

    :raise: a :exc:`NuSMVNoReadModelError
            <pynusmv.exception.NuSMVNoReadModelError>` if no model is read yet
    :raise: a :exc:`NuSMVCannotFlattenError
            <pynusmv.exception.NuSMVCannotFlattenError>` if an error occurred
            during flattening
    :raise: a :exc:`NuSMVModelAlreadyFlattenedError
            <pynusmv.exception.NuSMVModelAlreadyFlattenedError>` if the model
            is already flattened

    .. warning:: In case of type checking errors, a message is printed at
       stderr and a :exc:`NuSMVCannotFlattenError
       <pynusmv.exception.NuSMVCannotFlattenError>` is raised.

    """

    # Check cmps
    if not nscompile.cmp_struct_get_read_model(global_compile_cmps()):
        raise NuSMVNoReadModelError("Cannot flatten; no read model.")

    if nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()):
        raise NuSMVModelAlreadyFlattenedError("Model already flattened.")

    # Update options to reflect keep_single_enum
    if keep_single_enum:
        nsopt.set_keep_single_value_vars(nsopt.OptsHandler_get_instance())
    else:
        nsopt.unset_keep_single_value_vars(nsopt.OptsHandler_get_instance())

    # Flatten hierarchy
    ret = nscompile.flatten_hierarchy()
    if ret != 0:
        raise NuSMVCannotFlattenError("Cannot flatten the model.")

    global __symb_table
    __symb_table = SymbTable(nscompile.Compile_get_global_symb_table())
Example #7
0
def go_bmc(force=False):
    """
    Performs all the necessary steps to use loaded model and be able to perform
    bmc related operations on it.
    
    :raises NuSMVNoReadModelError: if no module was read (:func:`pynusmv.glob.load`) 
      before this method was called. 
    """
    cmp = glob.global_compile_cmps() 
    if not _compile.cmp_struct_get_read_model(cmp):
        raise NuSMVNoReadModelError("No read model.")

    # Check cmps and perform what is needed
    if not _compile.cmp_struct_get_flatten_hrc(cmp):
        glob.flatten_hierarchy()
    if not _compile.cmp_struct_get_encode_variables(cmp):
        glob.encode_variables()
    if not _compile.cmp_struct_get_build_bool_model(cmp):
        glob.build_boolean_model(force=force)
    if not _compile.cmp_struct_get_bmc_setup(cmp):
        bmc_setup(force=force)
Example #8
0
def build_flat_model():
    """
    Build the Sexp FSM (Simple Expression FSM) of the current model and store
    it in global data structures.

    :raise: a :exc:`NuSMVNeedFlatHierarchyError
            <pynusmv.exception.NuSMVNeedFlatHierarchyError>` if the model is
            not flattened
    :raise: a :exc:`NuSMVFlatModelAlreadyBuiltError
            <pynusmv.exception.NuSMVFlatModelAlreadyBuiltError>` if the Sexp
            FSM is already built

    """
    # Check cmps
    if not nscompile.cmp_struct_get_flatten_hrc(global_compile_cmps()):
        raise NuSMVNeedFlatHierarchyError("Need flat hierarchy.")
    if nscompile.cmp_struct_get_build_flat_model(global_compile_cmps()):
        raise NuSMVFlatModelAlreadyBuiltError(
            "The flat model is already built.")

    # Simplify the model
    st = nscompile.Compile_get_global_symb_table()
    layer = nssymb_table.SymbTable_get_layer(st, "model")
    ite = nssymb_table.gen_iter(layer, nssymb_table.STT_VAR)
    variables = nssymb_table.SymbLayer_iter_to_set(layer, ite)

    sexp_fsm = nsfsm.FsmBuilder_create_scalar_sexp_fsm(
        nscompile.Compile_get_global_fsm_builder(),
        global_compile_flathierarchy(), variables)

    nsset.Set_ReleaseSet(variables)

    nsprop.PropDb_master_set_scalar_sexp_fsm(
        nsprop.PropPkg_get_prop_database(), sexp_fsm)

    # Update cmps
    nscompile.cmp_struct_set_build_flat_model(global_compile_cmps())