Skip to content

result.py

from pymwp import Result

Result defines all information collected about an analyzed program.

FuncLoops

FuncLoops(name: str = None)

Bases: Timeable, Serializable

Analysis result for a function with loops, when running loop analysis mode. FuncLoops captures the results for all loops inside their parent function.

Attributes:

Name Type Description
name str

Containing function name.

loops Dict[str, LoopResult]

Function loop analysis results.

n_loops property

n_loops: int

Number of analyzed loops

from_dict staticmethod

from_dict(**kwargs) -> FuncLoops

Restore FuncLoops object.

FuncResult

FuncResult(
    name: str,
    infinite: bool = False,
    variables: Optional[List[str]] = None,
    relation: Optional[Relation] = None,
    choices: Optional[Choices] = None,
    bound: Optional[Bound] = None,
    inf_flows: Optional[str] = None,
    index: int = -1,
    func_code: str = None,
)

Bases: Timeable, Serializable

Analysis results for one function of the input program.

Attributes:

Name Type Description
name str

Function name.

infinite bool

True if no valid derivation exists.

variables List[str]

List of program variables.

relation Relation

Relation object; does not

choices Choices

A choice vector-object.

bound Bound

A bound of mwp-bounds.

inf_flows str

Description of problematic flows.

index int

Degree of derivation choice.

func_code str

Function source code.

n_bounds property

n_bounds: int

Number of bounds.

n_vars property

n_vars: int

Number of variables.

from_dict staticmethod

from_dict(name: str = None, **kwargs) -> FuncResult

Deserialize a function result.

to_dict

to_dict() -> dict

Serialize a function result.

LoopResult

LoopResult(loop_code: str = None)

Bases: Timeable, Serializable

Analysis result for one loop.

Attributes:

Name Type Description
loop_code str

The analyzed loop.

variables Dict[str, VResult]

Results by variable.

as_bound property

as_bound: Bound

Combines variable results to a Bound-type.

exp property

exp: List[str]

All variables with an unknown bound.

linear property

linear: List[str]

All variables with a linear bound.

loop_desc property

loop_desc: str

Loop description => header block.

n_bounded property

n_bounded: int

Number of variables with a known bound.

n_lines property

n_lines: int

Number of code lines in a loop.

n_vars property

n_vars: int

Number of variables.

poly property

poly: List[str]

All variables with a polynomial bound.

weak property

weak: List[str]

All variables with a weak polynomial bound.

from_dict staticmethod

from_dict(**kwargs) -> LoopResult

Restore LoopResult object.

var_sat

var_sat(cond: Callable[[VResult], bool]) -> List[str]

List of variables satisfying a condition.

Program

Program(
    program_path: str = None,
    n_lines: int = -1,
    n_func: int = 0,
    n_loops: int = 0,
    n_func_vars: int = 0,
    n_loop_vars: int = 0,
)

Bases: Serializable

Details about analyzed C-language input file.

Attributes:

Name Type Description
program_path str

Path to program file.

n_lines int

Lines of code in input program.

n_func int

Total functions (incl. un-analyzed).

n_loops int

Total loops (incl. un-analyzed).

n_func_vars int

Total function variables (incl. un-analyzed).

n_loop_vars int

Total loop variables (incl. un-analyzed).

name property

name: Optional[str]

Get program name without path and extension.

from_dict staticmethod

from_dict(**kwargs) -> Program

Restore Program object.

Result

Result()

Bases: Timeable, Serializable

Captures analysis result and details about the analysis process.

Attributes:

Name Type Description
program Program

Information about analyzed C File.

relations Dict[str, FuncResult]

Dictionary of function results.

loops Dict[str, FuncLoops]

Dictionary of function loop results.

n_functions property

n_functions: int

Number of analyzed functions in program.

n_loops property

n_loops: int

Number of analyzed loops in program.

add_loop

add_loop(result: FuncLoops) -> None

Append loop analysis to result.

add_relation

add_relation(result: FuncResult) -> None

Appends function analysis to result.

from_dict staticmethod

from_dict(**kwargs) -> Result

Restore Result object.

get_func

get_func(
    name: Optional[str] = None,
) -> Union[FuncResult, FuncLoops, Dict[str, FuncResult], Dict[str, FuncLoops]]

Returns analysis result for function(s).

Here "analysis" means either whole-function analysis, or loop analysis, based on executed analysis mode; they cannot co-exist in the same result.

  • If name argument is provided and key exists, returns a result for exact value match.
  • If program contained exactly 1 function, returns result for that function.
  • Otherwise, returns a dictionary of results for each analyzed function, as in: <function_name, analysis_result>

Parameters:

Name Type Description Default
name Optional[str]

Name of function.

None

Returns:

Type Description
Union[FuncResult, FuncLoops, Dict[str, FuncResult], Dict[str, FuncLoops]]

A function analysis result, or a dictionary of results.

log_result

log_result() -> Result

Display here all interesting stats about analysis result.

pretty_print staticmethod

pretty_print(
    txt: str, line_w: int = 50, hb: str = "─", color: bool = False
) -> str

Draws a colored box around text before display.

Parameters:

Name Type Description Default
txt str

Some text to display.

required
line_w int

Formatted text line width.

50
hb str

Horizontal bar box-drawing character

'─'
color bool

Apply color to output

False

Returns:

Type Description
str

Formatted text.

Serializable

Bases: ABC

General utilities for converting results to JSON-writable objects and vice versa.

from_dict abstractmethod staticmethod

from_dict(**kwargs) -> Serializable

Restore object from a dictionary; reverses to_dict().

to_dict

to_dict() -> Dict[str, Any]

Convert an object to a JSON-compatible dictionary.

Timeable

Timeable()

Represents an entity whose runtime can be measured.

Attributes:

Name Type Description
start_time int

recorded start time.

end_time int

recorded end time.

dur_ms property

dur_ms: int

Duration in milliseconds.

dur_s property

dur_s: float

Duration in seconds.

time_diff property

time_diff: int

Time delta between analysis start and end time.

on_end

on_end() -> Timeable

Called at end of timeable entity.

on_start

on_start() -> Timeable

Called at start of timeable entity.

VResult

VResult(
    name: str = None,
    is_m: bool = False,
    is_w: bool = False,
    is_p: bool = False,
    bound: MwpBound = None,
    choices: Choices = None,
)

Bases: Serializable

Analysis result for a single variable.

Attributes:

Name Type Description
name str

Variable name.

is_m bool

Has maximal linear bound.

is_w bool

Has weak polynomial bound.

is_p bool

Has polynomial bound.

bound Optional[MwpBound]

A bound (if exists).

choices Optional[Choice]

Bound choices.

exponential property

exponential

Variable has no known bound (polynomial or less).

is_m property writable

is_m: bool

Variable has a max of linear bound.

is_p property writable

is_p: bool

Variable has a polynomial bound.

is_w property writable

is_w: bool

Variable has a weak polynomial bound.

from_dict staticmethod

from_dict(**kwargs) -> VResult

Restore VResult object.

to_dict

to_dict() -> dict

Serialize a VResult object.