Package: pycallgraphix
pycallgraphixpycallgraphix is a simple python package that enables users to easily visualize their python code structure. pycallgraphix takes standardcall graphpython packages a step further by allowing users to create a visual from only the functions they select. Users simply wrap the functions they wish to include with a pre-defined wrapper and pycallgraphix generates an image based on their connections.FeaturesCall graph visualization of selected python functions in a PNG formatIncludes the time spent running selected functions and the number of calls to selected functionsColor coded call graph image, based on the time spent running function callsOptional profiling of selected functions using cProfileInstallationDirectly install via pip as follows:pip install pycallgraphixAlternatively, clone a local copy of the repository to your computer:git clone https://github.com/FZJ-IEK3-VSA/pycallgraphixThen install pycallgraphix via pip as follows:cd pycallgraphix
pip install .Finally, run the unit tests to ensure it is installed correctly:python -m unittest test.test_store_calls
python -m unittest test.test_store_funcsBasic WorkflowA small example how to use pycallgraphix is as follows:importcProfilefrompycallgraphix.wrapperimportMethodChart,register_methodEnable the profiler (optional):profiler=cProfile.Profile()profiler.enable()Define the call graph object. The execute function contains all the scripts or functions you wish to include in the graph. Scripts and functions do not need to be a part of the PyCallGraphObject class but all functions included in the call graph must be wrapped with the@register_methodwrapper:classPyCallGraphObject:def__init__(self)->None:self.execute()methodchart=MethodChart()methodchart.make_graphviz_chart(time_resolution=3,filename="Method_Pattern.png")profiler.disable()profiler.dump_stats("profile.prof")defexecute(self):self.sum_recursive(3,4)@register_methoddefsum_recursive(self,a,b):ifb>0:a+=1b-=1self.print_value(prefix='current',value=a)returnself.sum_recursive(a,b)else:self.print_value(prefix='final',value=a)returna@register_methoddefprint_value(self,prefix,value):print("{}value ={}".format(prefix,value))Finally run the code by initializing the PyCallGraphObject:run=PyCallGraphObject()If created succesfully, the resulting graph looks like:Including functions from other directories and scriptsTo include functions from other python files and scripts, simply import the wrapper into your script as follows:frompycallgraphix.wrapperimportregister_methodAnd wrap the desired functions. pycallgraphix will automatically locate it when creating the call graph:@register_methoddefmyExampleFunction(a,b):....Detailed ExampleA detailed example of what can be created with pycallgraphix was generated for one module of the House Infrastructure Simulator(HiSim).LicenseMIT LicenseCopyright (c) 2022-2023 Katharina Rieck (FZJ/IEK-3), Matthew Keller (FZJ/IEK-3), Noah Pflugradt (FZJ/IEK-3), Jann Weinand (FZJ/IEK-3), Detlef Stolten (FZJ/IEK-3)You should have received a copy of the MIT License along with this program.
If not, seehttps://opensource.org/licenses/MITAbout UsWe are theInstitute of Energy and Climate Research - Techno-economic Systems Analysis (IEK-3)belonging to theForschungszentrum Jülich. Our interdisciplinary department's research is focusing on energy-related process and systems analyses. Data searches and system simulations are used to determine energy and mass balances, as well as to evaluate performance, emissions and costs of energy systems. The results are used for performing comparative assessment studies between the various systems. Our current priorities include the development of energy strategies, in accordance with the German Federal Government’s greenhouse gas reduction targets, by designing new infrastructures for sustainable and secure energy supply chains and by conducting cost analysis studies for integrating new technologies into future energy market frameworks.AcknowledgmentsTo create the singleton pattern, the following work was referenced:https://refactoring.guru/design-patterns/singleton/python/example#example-1pycallgraphix makes use of thepython graphvizpackage.