added expe003 that shows that most equations found by sumfinder on alambix97 set were not confirmed on alambix98 set
This commit is contained in:
parent
34dd0bceb1
commit
6bcdade804
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
from pathlib import Path
|
||||||
|
from sumfinder import load_sums, remove_invalid_sums
|
||||||
|
from linuxmem import read_meminfo_stdout
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
sums = load_sums(Path('../expe001.5/alambix97-meminfo-sums.json'))
|
||||||
|
print(f'starting sums ({len(sums)} sums):')
|
||||||
|
print(sums)
|
||||||
|
|
||||||
|
variables = read_meminfo_stdout(Path('../bug3897/alambix98/20240806-223916-meminfo.stdout'))
|
||||||
|
# variables = read_meminfo_stdout(Path('../bug3897/alambix97/20240805-191606-meminfo.stdout'))
|
||||||
|
(valid_sums, invalid_sums) = remove_invalid_sums(sums, variables)
|
||||||
|
print(f'invalid sums ({len(invalid_sums)} sums):')
|
||||||
|
print(invalid_sums)
|
||||||
|
|
||||||
|
print(f'valid sums ({len(valid_sums)} sums):')
|
||||||
|
print(valid_sums)
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
|
@ -1,4 +1,7 @@
|
||||||
|
from .sumfinder import Sums # noqa
|
||||||
from .sumfinder import SumExporter # noqa
|
from .sumfinder import SumExporter # noqa
|
||||||
|
from .sumfinder import load_sums # noqa
|
||||||
from .sumfinder import find_sums # noqa
|
from .sumfinder import find_sums # noqa
|
||||||
from .sumfinder import sums_to_dot # noqa
|
from .sumfinder import sums_to_dot # noqa
|
||||||
from .sumfinder import find_and_graph_sums # noqa
|
from .sumfinder import find_and_graph_sums # noqa
|
||||||
|
from .sumfinder import remove_invalid_sums # noqa
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# given a list of integer variables and their values, this tool aims at finding which varibales can be obtained by the sum of others
|
# given a list of integer variables and their values, this tool aims at finding which varibales can be obtained by the sum of others
|
||||||
# note : this tool is used to find the sums in the variables output by /proc/meminfo
|
# note : this tool is used to find the sums in the variables output by /proc/meminfo
|
||||||
from typing import Dict, List, Set
|
from typing import Dict, List, Set, Tuple
|
||||||
import abc
|
import abc
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
|
@ -9,6 +9,7 @@ import subprocess
|
||||||
|
|
||||||
VarName = str
|
VarName = str
|
||||||
VarValue = int
|
VarValue = int
|
||||||
|
Sums = List[Dict[VarName, List[VarName]]]
|
||||||
|
|
||||||
|
|
||||||
class IntVariable():
|
class IntVariable():
|
||||||
|
@ -48,7 +49,7 @@ class SumExporter(ISumHandler):
|
||||||
'''
|
'''
|
||||||
sum_file_path: Path
|
sum_file_path: Path
|
||||||
variables: Set[IntVariable]
|
variables: Set[IntVariable]
|
||||||
sums: List[Dict[VarName, List[VarName]]]
|
sums: Sums
|
||||||
|
|
||||||
def __init__(self, sum_file_path: Path):
|
def __init__(self, sum_file_path: Path):
|
||||||
self.sum_file_path = sum_file_path
|
self.sum_file_path = sum_file_path
|
||||||
|
@ -71,6 +72,13 @@ class SumExporter(ISumHandler):
|
||||||
self.sum_file_path.write_text(json.dumps(root_dict))
|
self.sum_file_path.write_text(json.dumps(root_dict))
|
||||||
|
|
||||||
|
|
||||||
|
def load_sums(sums_file_path: Path) -> Sums:
|
||||||
|
with open(sums_file_path, 'rt', encoding='utf8') as sums_file:
|
||||||
|
root_dict = json.loads(sums_file.read())
|
||||||
|
assert root_dict['format'] == 'sums-v001'
|
||||||
|
return root_dict['sums']
|
||||||
|
|
||||||
|
|
||||||
def explore(total: IntVariable, components: List[IntVariable], cur_sum: VarValue, cur_var_index: int, contrib_components: List[IntVariable], sum_handler: ISumHandler):
|
def explore(total: IntVariable, components: List[IntVariable], cur_sum: VarValue, cur_var_index: int, contrib_components: List[IntVariable], sum_handler: ISumHandler):
|
||||||
# for i in range(cur_var_index):
|
# for i in range(cur_var_index):
|
||||||
# print(' ', end='')
|
# print(' ', end='')
|
||||||
|
@ -290,3 +298,25 @@ def find_and_graph_sums(variables: Dict[str, int], set_id: str):
|
||||||
sums_to_dot(sums_file_path, dot_file_path)
|
sums_to_dot(sums_file_path, dot_file_path)
|
||||||
print(f'creating {svg_file_path} from {dot_file_path}')
|
print(f'creating {svg_file_path} from {dot_file_path}')
|
||||||
subprocess.run(f'dot -Tsvg {dot_file_path} > {svg_file_path}', shell=True, check=True)
|
subprocess.run(f'dot -Tsvg {dot_file_path} > {svg_file_path}', shell=True, check=True)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_invalid_sums(input_sums: Sums, variables: Dict[VarName, VarValue]) -> Tuple[Sums, Sums]:
|
||||||
|
"""
|
||||||
|
returns the tuple valid_sums, invalid_sums after checking each of the sum of input_sum againts the given variables
|
||||||
|
"""
|
||||||
|
valid_sums: Sums = []
|
||||||
|
invalid_sums: Sums = []
|
||||||
|
for _sum in input_sums:
|
||||||
|
# for total_var_id, components in input_sums.items():
|
||||||
|
total_var_id = _sum['total']
|
||||||
|
components = _sum['components']
|
||||||
|
|
||||||
|
computed_total_value = 0
|
||||||
|
for component_var_id in components:
|
||||||
|
computed_total_value += variables[component_var_id]
|
||||||
|
real_total_value = variables[total_var_id]
|
||||||
|
if computed_total_value == real_total_value:
|
||||||
|
valid_sums.append(_sum)
|
||||||
|
else:
|
||||||
|
invalid_sums.append(_sum)
|
||||||
|
return (valid_sums, invalid_sums)
|
||||||
|
|
Loading…
Reference in New Issue