Skip to content
Snippets Groups Projects
Commit 08c70ef1 authored by Rahil Doshi's avatar Rahil Doshi
Browse files

Python Call Graph generation scripts and visualizations

parent 669fa454
No related merge requests found
Pipeline #75839 passed with stage
in 23 seconds
import os
from pycallgraph2 import PyCallGraph, Config
from pycallgraph2.output import GraphvizOutput
from pycallgraph2.globbing_filter import GlobbingFilter
# Define the path to the folder inside the apps directory
apps_directory = '/local/ca00xebo/repos/pymatlib/apps'
image_folder = os.path.join(apps_directory, 'callgraph_images')
# Create the folder if it does not exist
if not os.path.exists(image_folder):
os.makedirs(image_folder)
# Create configuration to focus on your specific functions
config = Config()
config.trace_filter = GlobbingFilter(
include=[
'pymatlib.core.interpolators.*',
'pymatlib.core.data_handler.*',
'InterpolationArrayContainer.*',
'assignment_converter',
'interpolate_property',
'check_equidistant',
'check_strictly_increasing',
],
exclude=[
'pycallgraph2.*',
'*.append', # Exclude common methods
'*.join',
]
)
# Configure the output with the full path
output_file = os.path.join(image_folder, 'array_container_callgraph.svg')
# Configure the output
graphviz = GraphvizOutput(
output_file=output_file,
font_name='Verdana',
font_size=7,
group_stdlib=True,
output_type='svg',
dpi=1200
)
# Run the specific part of your code with call graph tracking
with PyCallGraph(config=config, output=graphviz):
import numpy as np
from pystencils import fields
from importlib.resources import files
from pystencilssfg import SourceFileGenerator
from pymatlib.core.yaml_parser import create_alloy_from_yaml
from pymatlib.core.interpolators import InterpolationArrayContainer
with SourceFileGenerator() as sfg:
u = fields(f"u: double[2D]", layout='fzyx')
T_bs = np.array([3243.15, 3248.15, 3258.15, 3278.15], dtype=np.float64)
E_bs = np.array([1.68e10, 1.69e10, 1.70e10, 1.71e10], dtype=np.float64)
custom_container = InterpolationArrayContainer("BinarySearchTests", T_bs, E_bs)
sfg.generate(custom_container)
T_eq = np.array([3243.15, 3253.15, 3263.15, 3273.15], dtype=np.float64)
E_neq = np.array([1.68e10, 1.69e10, 1.70e10, 1.71e10], dtype=np.float64)
custom_container = InterpolationArrayContainer("DoubleLookupTests", np.flip(T_eq), np.flip(E_neq))
sfg.generate(custom_container)
yaml_path = files('pymatlib.data.alloys.SS304L').joinpath('SS304L_comprehensive.yaml')
mat = create_alloy_from_yaml(yaml_path, u.center())
arr_container = InterpolationArrayContainer.from_material("SS304L", mat)
sfg.generate(arr_container)
This diff is collapsed.
This diff is collapsed.
import os
import sys
sys.path.append('/local/ca00xebo/repos/pymatlib')
from pycallgraph2 import PyCallGraph, Config
from pycallgraph2.output import GraphvizOutput
from pycallgraph2.globbing_filter import GlobbingFilter
# Import necessary modules once
import sympy as sp
import pystencils as ps
from importlib.resources import files
from pystencilssfg import SourceFileGenerator
from pymatlib.core.yaml_parser import create_alloy_from_yaml
from pymatlib.core.interpolators import InterpolationArrayContainer
from pymatlib.core.assignment_converter import assignment_converter
# Define the path to the folder inside the apps directory
apps_directory = '/local/ca00xebo/repos/pymatlib/apps'
image_folder = os.path.join(apps_directory, 'callgraph_images')
# Create the folder if it does not exist
if not os.path.exists(image_folder):
os.makedirs(image_folder)
# Function to create a visualization for a specific target
def create_visualization(target_name, include_patterns, output_filename):
print(f"Generating visualization for {target_name}...")
# Create the full path for the output file
output_file = os.path.join(image_folder, output_filename)
# Create configuration
config = Config(max_depth=10)
config.trace_filter = GlobbingFilter(
include=include_patterns,
exclude=[
'pycallgraph2.*',
'*.append',
'*.join',
]
)
# Configure the output
graphviz = GraphvizOutput(
output_file=output_file,
font_name='Verdana',
font_size=7,
group_stdlib=True,
output_type='svg',
dpi=400
)
# Create minimal setup for all visualizations
u = ps.fields("u: float64[2D]", layout='fzyx')
yaml_path = files('pymatlib.data.alloys.SS304L').joinpath('SS304L_comprehensive.yaml')
# Run the appropriate code based on the target
with PyCallGraph(config=config, output=graphviz):
if target_name == "create_alloy_from_yaml":
mat = create_alloy_from_yaml(yaml_path, u.center())
elif target_name == "InterpolationArrayContainer":
mat = create_alloy_from_yaml(yaml_path, u.center())
arr_container = InterpolationArrayContainer.from_material("SS304L", mat)
with SourceFileGenerator() as sfg:
sfg.generate(arr_container)
elif target_name == "assignment_converter":
mat = create_alloy_from_yaml(yaml_path, u.center())
thermal_diffusivity = sp.Symbol("thermal_diffusivity")
subexp, subs = assignment_converter(mat.thermal_diffusivity.assignments)
subexp.append(ps.Assignment(thermal_diffusivity, mat.thermal_diffusivity.expr))
print(f"Visualization saved to {output_file}")
# Generate each visualization
create_visualization(
"create_alloy_from_yaml",
['pymatlib.core.yaml_parser.*', 'create_alloy_from_yaml'],
'create_alloy_callgraph.svg'
)
create_visualization(
"InterpolationArrayContainer",
['pymatlib.core.interpolators.*', 'InterpolationArrayContainer.*'],
'array_container_callgraph.svg'
)
create_visualization(
"assignment_converter",
['pymatlib.core.assignment_converter.*', 'assignment_converter'],
'assignment_converter_callgraph.svg'
)
print("All visualizations completed.")
import os
from pycallgraph2 import PyCallGraph, Config
from pycallgraph2.output import GraphvizOutput
from pycallgraph2.globbing_filter import GlobbingFilter
# Define the path to the folder inside the apps directory
apps_directory = '/local/ca00xebo/repos/pymatlib/apps'
image_folder = os.path.join(apps_directory, 'callgraph_images')
# Create the folder if it does not exist
if not os.path.exists(image_folder):
os.makedirs(image_folder)
# Create configuration to focus on your specific functions
config = Config()
config.trace_filter = GlobbingFilter(
include=[
'pymatlib.core.alloy.*',
'pymatlib.core.elements.*',
'pymatlib.core.yaml_parser.*',
'pymatlib.core.assignment_converter.*',
'pymatlib.core.interpolators.*',
'pymatlib.core.interpolators.interpolate_property.*',
'pymatlib.core.typedefs.*',
'pymatlib.core.models.*',
'pymatlib.core.data_handler.*',
'InterpolationArrayContainer.*',
'create_alloy_from_yaml',
'assignment_converter',
'interpolate_property',
'Assignment',
'ArrayTypes',
'PropertyTypes',
'MaterialProperty',
'density_by_thermal_expansion',
'thermal_diffusivity_by_heat_conductivity',
'energy_density_standard',
'energy_density_enthalpy_based',
'energy_density_total_enthalpy',
'read_data_from_file',
'wrapper',
'check_equidistant',
'check_strictly_increasing',
'ChemicalElement',
'interpolate_atomic_mass',
'interpolate_atomic_number',
'interpolate_temperature_boil',
'evalf',
],
exclude=[
'pycallgraph2.*',
'*.append', # Exclude common methods
'*.join',
]
)
# Configure the output with the full path
output_file = os.path.join(image_folder, 'yaml_parser_callgraph.svg')
# Configure the output
graphviz = GraphvizOutput(
output_file=output_file,
font_name='Verdana',
font_size=7,
group_stdlib=True,
output_type='svg',
dpi=1200
)
# Run the specific part of your code with call graph tracking
with PyCallGraph(config=config, output=graphviz):
# Import necessary modules
import sympy as sp
import pystencils as ps
from importlib.resources import files
# from pystencilssfg import SourceFileGenerator
# from pymatlib.core.assignment_converter import assignment_converter
# from pymatlib.core.interpolators import InterpolationArrayContainer
from pymatlib.core.yaml_parser import create_alloy_from_yaml
u = ps.fields("u: float64[2D]", layout='fzyx')
yaml_path = files('pymatlib.data.alloys.SS304L').joinpath('SS304L_comprehensive.yaml')
mat = create_alloy_from_yaml(yaml_path, u.center())
'''with SourceFileGenerator() as sfg:
yaml_path = files('pymatlib.data.alloys.SS304L').joinpath('SS304L.yaml')
mat = create_alloy_from_yaml(yaml_path, u.center())
arr_container = InterpolationArrayContainer.from_material("SS304L", mat)
sfg.generate(arr_container)
# Convert assignments to pystencils format
subexp, subs = assignment_converter(mat.thermal_diffusivity.assignments)
thermal_diffusivity = sp.Symbol("thermal_diffusivity")
subexp.append(ps.Assignment(thermal_diffusivity, mat.thermal_diffusivity.expr))'''
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment