Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

688 explorer enable export of pegraph in gephi compatible format via command line argument #690

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions discopop_explorer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def parse_args() -> ExplorerArguments:
experimental_parser.add_argument(
"--enable-statistics", action="store_true", help="Disable the calculation and storing of statistics for code and generated suggestions."
)
experimental_parser.add_argument(
"--plot-pet", type=str, nargs="?", default=None, const="explorer/pet_plot.gexf",
help="Plots PET as a GEXF file. If a path is given (file extension has to be .gexf), the PET Graph is written to the given file, otherwise to pet_plot.gexf"
)
# fmt: on

arguments = parser.parse_args()
Expand Down Expand Up @@ -135,6 +139,7 @@ def parse_args() -> ExplorerArguments:
arguments.dump_pet = get_path_or_none(arguments.path, arguments.dump_pet)
arguments.dump_detection_result = get_path_or_none(arguments.path, arguments.dump_detection_result)
arguments.microbench_file = get_path_or_none(arguments.path, arguments.microbench_file)
arguments.plot_pet = get_path_or_none(arguments.path, arguments.plot_pet)

return ExplorerArguments(
discopop_build_path=arguments.dp_build_path,
Expand Down Expand Up @@ -162,6 +167,7 @@ def parse_args() -> ExplorerArguments:
load_existing_doall_and_reduction_patterns=arguments.load_existing_doall_and_reduction_patterns,
collect_statistics=arguments.enable_statistics,
jobs=arguments.jobs,
enable_pet_plot_file=arguments.plot_pet,
)


Expand Down
7 changes: 7 additions & 0 deletions discopop_explorer/discopop_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pstats2 # type:ignore
from pluginbase import PluginBase # type: ignore
from discopop_explorer.functions.PEGraph.output.json import dump_to_pickled_json
from discopop_explorer.functions.PEGraph.output.gephi import dump_to_gephi_file
from discopop_explorer.utilities.statistics.collect_statistics import collect_statistics
from discopop_library.ArgumentClasses.GeneralArguments import GeneralArguments # type: ignore
from discopop_library.FolderStructure.setup import setup_explorer
Expand Down Expand Up @@ -74,6 +75,7 @@ class ExplorerArguments(GeneralArguments):
microbench_file: Optional[str]
load_existing_doall_and_reduction_patterns: bool
collect_statistics: bool
enable_pet_plot_file: Optional[str] # None means no dump, otherwise the path

def __post_init__(self) -> None:
self.__validate()
Expand Down Expand Up @@ -258,6 +260,11 @@ def run(arguments: ExplorerArguments) -> None:
f.flush()
f.close()

# experimental
# dumps gexf plot of pet
if arguments.enable_pet_plot_file is not None:
dump_to_gephi_file(res.pet, arguments.enable_pet_plot_file)

if arguments.enable_detection_result_dump_file is not None:
with open(arguments.enable_detection_result_dump_file, "w+") as f:
f.write(res.dump_to_pickled_json())
Expand Down
2 changes: 1 addition & 1 deletion discopop_explorer/functions/PEGraph/output/gephi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import networkx as nx # type: ignore


def dump_to_gephi_file(pet: PEGraphX, name: str = "pet.gexf") -> None:
def dump_to_gephi_file(pet: PEGraphX, name: str) -> None:
"""Note: Destroys the PETGraph!"""
# replace node data with label
for node_id in pet.g.nodes:
Expand Down