Example #1
0
def crack_init(spec_files):
    com_args = {}
    phases = {}
    tasks = []
    for spec_file in spec_files:
        with open(spec_file, "r") as f:
            specs = yaml.load(f)
        if "with" in specs:
            com_args = merge_dicts(com_args, specs["with"])
        if "phases" in specs:
            phases = merge_dicts(phases, specs["phases"])
            format_args(phases, com_args)
        if "do" in specs:
            tasks.extend(specs["do"])
    phases_index = {}
    for i, task in enumerate(tasks):
        tasks[i] = format_task(task, phases, phases_index, com_args, i)
    phases_index["end"] = -1
    return tasks, phases_index
Example #2
0
def record_algos_stats(models,
                       records,
                       algo,
                       cut=None,
                       imb=None,
                       t=None,
                       operations=None,
                       **algopt):
    stats = {
        "algo": algo,
        "cut": cut,
        "imb": imb,
        "time": t,
        "operations": operations,
    }
    if t is not None:
        records["time"] += t
    if operations is not None:
        records["operations"] += operations

    records["per_algo"].append(merge_dicts(stats, algopt))
Example #3
0
def format_task(task, phases, phases_index, com_args, i):
    """Get algorithm id, args and next phase.
    """
    if isinstance(task, str):
        if task in phases:
            algo = phases[task]["algo"]
            args = phases[task].get("args", {})
            format_args(args, com_args)
            next_phase = phases[task].get("next")
            phases_index[task] = i
        else:
            algo = task
            args = {}
            next_phase = None
            phases_index[algo] = i
    elif isinstance(task, dict):
        if "phase" in task:
            phase_id = task["phase"]
            if "algo" in task:
                algo = task["algo"]
            else:
                algo = phases[phase_id]["algo"]
            args = task.get("args", {})
            format_args(args, com_args)
            args = merge_dicts(phases[phase_id].setdefault("args", {}), args)
            next_phase = task
            phases_index[phase_id] = i
        else:  # task is of type {algo_name: {**args}}
            algo = list(task)[0]  # (should only be one key: the algo name)
            args = task[algo]
            format_args(args, com_args)
            next_phase = None
            phases_index[algo] = i
    phase = {
        "algo": algo,
        "args": args,
        "next": next_phase,
    }
    return phase
Example #4
0
from crack.models.graph import INIT_GRAPH_FCTS, INIT_GRAPHGEOM_FCTS, OUTPUT_GRAPH_FCTS
from crack.models.hypergraph import INIT_HYPERGRAPH_FCTS
from crack.models.mesh import INIT_MESH_FCTS
from crack.models.partition import INIT_PARTITION_FCTS
from crack.models.nweights import INIT_NWGT_FCTS
from crack.models.eweights import INIT_EWGT_FCTS

from crack.models.cut import cut_lambda_minus_one, gain__cut_lambda_minus_one__graph, gain__cut_lambda_minus_one__hypergraph
from crack.models.imbalance import ConstraintsImbalance, imbalance

from crack.utils.errors import crack_error
from crack.utils.structures import merge_dicts

INIT_FCTS = merge_dicts(INIT_GRAPH_FCTS, INIT_GRAPHGEOM_FCTS,
                        INIT_HYPERGRAPH_FCTS, INIT_MESH_FCTS, INIT_NWGT_FCTS,
                        INIT_EWGT_FCTS, INIT_PARTITION_FCTS)

OUTPUT_FCTS = merge_dicts(OUTPUT_GRAPH_FCTS, )

CONSTRAINTS_OBJ = {
    "imbalance": ConstraintsImbalance,
}


def get_obj_fcts(models, obj_name, obj_args):
    """How to compute the values (e.g. cut, imbalance) that the user
    usually wants to minimize.
    """
    obj_fct = None
    if obj_name == "cut":
Example #5
0
import random as rd
import sys
import yaml

from crack.algos.algos_fcts import ALGOS
from crack.analysis.analysis_fcts import ANALYZE_FCTS
from crack.models.models_fcts import INIT_FCTS, OUTPUT_FCTS
from crack.operators.coarsen import COARSEN_FCTS
from crack.operators.prolong import PROLONG_FCTS
from crack.utils.fork import FORK_FCTS
from crack.utils.structures import merge_dicts
from crack.utils.evaluate import eval_expr
from crack.utils.errors import crack_error
from crack.utils.algo_utils import init_algos_stats

NORMAL_FCTS = merge_dicts(ALGOS, ANALYZE_FCTS, INIT_FCTS, OUTPUT_FCTS)


def format_args(args, com_args):
    if "with" in args:
        for com_k, com_v in com_args[args["with"]].items():
            args.setdefault(com_k, com_v)
        del args["with"]
    for k, v in args.items():
        if isinstance(v, dict):
            format_args(v, com_args)


def get_next_phase(l_models, records, tasks, phase_index, next_phase):
    """Analyse the fork conditions and return the next Phase.
    """