radical-cybertools / radical.analytics

Analytics for RADICAL-Cybertools
Other
1 stars 1 forks source link

Differentiate/Filter Radical Analytics data by type/ID of task #177

Closed okilic1 closed 8 months ago

okilic1 commented 11 months ago

To allow plotting graphs based on the types of the task via either color coding or filtering.

okilic1 commented 11 months ago

@andre-merzky you can find both script and the sandbox in following directories Script: https://github.com/okilic1/asyncExecution/blob/main/figures/resource_utilization-summit-Adaptive.ipynb Sandbox: https://github.com/okilic1/asyncExecution/tree/main/rawdata

andre-merzky commented 8 months ago

Ozgur - this standalone version (which is a copy of the notebook code) seems to do what is expected: it results in three valid sessions, and the entities are sorted as expected. Gan you give this a try, please?

#!/usr/bin/env python3

import os
import tarfile
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

import radical.utils as ru
import radical.pilot as rp
import radical.entk as re
import radical.analytics as ra

plt.style.use(ra.get_mplstyle('radical_mpl'))

from IPython.display import display, HTML
mpl.rcParams['figure.dpi']= 600

metrics = [
    ['Bootstrap', ['boot', 'setup_1']                         , '#c6dbef'],
    ['Warmup'   , ['warm' ]                                   , '#f0f0f0'],
    ['Schedule' , ['exec_queue','exec_prep', 'unschedule']    , '#c994c7'],
    ['Exec RP'  , ['exec_rp', 'exec_sh', 'term_sh', 'term_rp'], '#fdbb84'],
    ['Exec Cmd' , ['exec_cmd']                                , '#e31a1c'],
    ['Cooldown' , ['drain']                                   , '#addd8e']
]
metrics = [
    ['Bootstrap', ['boot', 'setup_1']                         , '#ffffff'],
    ['Warmup'   , ['warm' ]                                   , '#ffffff'],
    ['Schedule' , ['exec_queue','exec_prep', 'unschedule']    , '#ffffff'],
    ['Exec RP'  , ['exec_rp', 'exec_sh', 'term_sh', 'term_rp'], '#ffffff'],
    ['Exec Cmd' , ['exec_cmd']                                , '#839dc9'],
    ['Cooldown' , ['drain']                                   , '#ffffff']
]

## Weak Scaling

#os.environ['RADICAL_PILOT_DBURL'] = 'mongodb://pascuzzi:slriUTnc7NrM8o5t@95.217.193.116/lavinlie'

### Adaptive Experiment
# rp.session.login3.okilic1.019534.0004 #=> Sync --debug
# rp.session.login3.okilic1.019534.0007 #=> Workload Async --debug
# rp.session.login3.okilic1.019534.0010 #=> Task Async --debug

# rp.session.login3.okilic1.019534.0012 #=> Sync --Full
# rp.session.login3.okilic1.019534.0013 #=> Workload Async --Full
# rp.session.login3.okilic1.019534.0014 #=> Task Async --Full

sids = ['rp.session.login3.okilic1.019534.0004',#, #=> Sync --debug
        'rp.session.login3.okilic1.019534.0007', #=> Workload Async --debug
        'rp.session.login3.okilic1.019534.0010', #=> Task Async --debug

        'rp.session.login3.okilic1.019534.0012', #=> Sync --Full
        'rp.session.login3.okilic1.019534.0013', #=> Workload Async --Full
        'rp.session.login3.okilic1.019534.0014'] #=> Task Async --Full

#sids =  ['rp.session.login2.okilic1.019489.0011', # dg2-asyn
#         'rp.session.login4.okilic1.019489.0010'] # dg1-asyn
#sids = ['rp.session.login4.okilic1.019489.0010', # dg1-asyn
#        'rp.session.login2.okilic1.019489.0011', # dg2-asyn
#        'rp.session.login4.okilic1.019489.0010', # dg1-asyn
#        'rp.session.login2.okilic1.019489.0011'] # dg2-asyn
sdir = '../rawdata/'
sessions = [sdir + s for s in sids]

for sid in sids:
    sp = sdir+sid+'.tgz'
    tar = tarfile.open(sp, mode='r:gz')
    tar.extractall(path=sdir)
    tar.close()

ss = {}
for sid in sids:
    sp = sdir + sid
    ss[sid] = {'s': ra.Session(sp, 'radical.pilot')}
    ss[sid].update({'p': ss[sid]['s'].filter(etype='pilot', inplace=False),
                    't': ss[sid]['s'].filter(etype='task' , inplace=False)})

    print()
    print(sid, sp, ss[sid]['s'], ss[sid]['p'], ss[sid]['t'])
    print(ss[sid]['s'])
    print(ss[sid]['p'])
    print(ss[sid]['t'])
  # print([e.uid for e in ss[sid]['s'].get()])
    print([e.uid for e in ss[sid]['p'].get()])
    print([e.uid for e in ss[sid]['t'].get()])
$ radical-stack
1698242234.548 : radical.analytics    : 287581 : 140188404437056 : INFO     : radical.analytics    version: 1.34.0-v1.34.0@HEAD-detached-at-v1.34.0

  python               : /home/merzky/radical/radical.analytics.devel/ve3/bin/python3
  pythonpath           :
  version              : 3.11.5
  virtualenv           : /home/merzky/radical/radical.analytics.devel/ve3

  radical.analytics    : 1.34.0-v1.34.0@HEAD-detached-at-v1.34.0
  radical.entk         : 1.37.0
  radical.gtod         : 1.20.1
  radical.pilot        : 1.37.0
  radical.saga         : 1.36.0
  radical.utils        : 1.33.0
okilic1 commented 8 months ago

Hi Andre, Filtering works, and I can get a filtered list of tasks when I change 't': ss[sid]['s'].filter(etype='task' , inplace=False)}) with 't': ss[sid]['s'].filter(uid=[pat1, pat2] , inplace=False)}) after setting the pat1 and pat2. However, I cannot get data using the filtered dictionary. Here is the code:

#!/usr/bin/env python3

import os
import tarfile
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

import radical.utils as ru
import radical.pilot as rp
import radical.entk as re
import radical.analytics as ra

import re as re1

plt.style.use(ra.get_mplstyle('radical_mpl'))

from IPython.display import display, HTML
mpl.rcParams['figure.dpi']= 600

metrics = [
    ['Bootstrap', ['boot', 'setup_1']                         , '#c6dbef'],
    ['Warmup'   , ['warm' ]                                   , '#f0f0f0'],
    ['Schedule' , ['exec_queue','exec_prep', 'unschedule']    , '#c994c7'],
    ['Exec RP'  , ['exec_rp', 'exec_sh', 'term_sh', 'term_rp'], '#fdbb84'],
    ['Exec Cmd' , ['exec_cmd']                                , '#e31a1c'],
    ['Cooldown' , ['drain']                                   , '#addd8e']
]
metrics = [
    ['Bootstrap', ['boot', 'setup_1']                         , '#ffffff'],
    ['Warmup'   , ['warm' ]                                   , '#ffffff'],
    ['Schedule' , ['exec_queue','exec_prep', 'unschedule']    , '#ffffff'],
    ['Exec RP'  , ['exec_rp', 'exec_sh', 'term_sh', 'term_rp'], '#ffffff'],
    ['Exec Cmd' , ['exec_cmd']                                , '#839dc9'],
    ['Cooldown' , ['drain']                                   , '#ffffff']
]

## Weak Scaling

#os.environ['RADICAL_PILOT_DBURL'] = 'mongodb://pascuzzi:slriUTnc7NrM8o5t@95.217.193.116/lavinlie'

### Adaptive Experiment
# rp.session.login3.okilic1.019534.0004 #=> Sync --debug
# rp.session.login3.okilic1.019534.0007 #=> Workload Async --debug
# rp.session.login3.okilic1.019534.0010 #=> Task Async --debug

# rp.session.login3.okilic1.019534.0012 #=> Sync --Full
# rp.session.login3.okilic1.019534.0013 #=> Workload Async --Full
# rp.session.login3.okilic1.019534.0014 #=> Task Async --Full

sids = ['rp.session.login3.okilic1.019534.0004']#, #=> Sync --debug
#        'rp.session.login3.okilic1.019534.0007', #=> Workload Async --debug
#        'rp.session.login3.okilic1.019534.0010', #=> Task Async --debug
#
#        'rp.session.login3.okilic1.019534.0012', #=> Sync --Full
#        'rp.session.login3.okilic1.019534.0013', #=> Workload Async --Full
#        'rp.session.login3.okilic1.019534.0014'] #=> Task Async --Full

#sids =  ['rp.session.login2.okilic1.019489.0011', # dg2-asyn
#         'rp.session.login4.okilic1.019489.0010'] # dg1-asyn
#sids = ['rp.session.login4.okilic1.019489.0010', # dg1-asyn
#        'rp.session.login2.okilic1.019489.0011', # dg2-asyn
#        'rp.session.login4.okilic1.019489.0010', # dg1-asyn
#        'rp.session.login2.okilic1.019489.0011'] # dg2-asyn
sdir = '../rawdata/'
sessions = [sdir + s for s in sids]

for sid in sids:
    sp = sdir+sid+'.tgz'
    tar = tarfile.open(sp, mode='r:gz')
    tar.extractall(path=sdir)
    tar.close()

pat1 = re1.compile(r'^t10\..*0$')
pat2 = re1.compile(r'^t4\..*0$')

ss = {}
for sid in sids:
    print("THIS IS SID: ", sid)
    sp = sdir + sid
    ss[sid] = {'s': ra.Session(sp, 'radical.pilot')}
    ss[sid].update({'p': ss[sid]['s'].filter(etype='pilot', inplace=False),
                    #'t': ss[sid]['s'].filter(uid=[pat1, pat2] , inplace=False)})
                    't': ss[sid]['s'].filter(etype='task' , inplace=False)})

    print()
    print(sid, sp, ss[sid]['s'], ss[sid]['p'], ss[sid]['t'])
    print(ss[sid]['s'])
    print(ss[sid]['p'])
    print(ss[sid]['t'])
  # print([e.uid for e in ss[sid]['s'].get()])
    print([e.uid for e in ss[sid]['p'].get()])
    print([e.uid for e in ss[sid]['t'].get()])

#This part I copied

#exp =  ss["rp.session.login3.okilic1.019534.0014"]
exp = ra.Experiment(sessions, stype='radical.pilot')
p_zeros = ra.get_pilots_zeros(exp)

# Type of resource we want to plot: cpu or gpu
rtypes=['cpu', 'gpu']

print("Metrics: ", metrics)
print("Types: ", rtypes)
provided, consumed, stats_abs, stats_rel, info = exp.utilization(metrics=metrics, rtype=rtypes[1])

print("provided: ", provided)
print("consumed: ", consumed)
print("stats_abs: ", stats_abs)
print("stats_rel: ", stats_rel)
print("info: ", info)

#for s in sessions:
#    print("path: ",os.path.basename(s))
# sessions you want to plot
splot = [os.path.basename(s) for s in sessions]
nsids = len(splot)

# Create figure and 1 subplot for each session
# Use LaTeX document page size (see RA Plotting Chapter)
fwidth, fhight = ra.get_plotsize(300, subplots=(1, 1))
fig, axarr = plt.subplots(2, 1, sharex='col', figsize=(fwidth, fhight))

# Avoid overlapping between Y-axes ticks and sub-figures
plt.subplots_adjust(wspace=0.45)

# Generate the subplots with labels

legend = None
for k, rtype in enumerate(rtypes):
    _, consumed, _, _, _ = exp.utilization(metrics=metrics, rtype=rtype)
    #print("consumed: ", consumed)
    j = 'a'
    #print("j: ",j)
    #print("splot3: ", splot[3:])
    #print("splot: ", splot)
    for i, sid in enumerate(splot[0:]):

        # we know we have only 1 pilot
        #pid = ss[sid]['t'].list('uid')[0]
        pid = ss[sid]['p'].list('uid')[0]
        print ("PID:: ",pid)
        print ("p_zeroes: ", p_zeros)

        # Plot legend, patched, X and Y axes objects
        legend, patches, x, y = ra.get_plot_utilization(metrics, consumed, p_zeros[sid][pid], sid)

        # Place all the patches, one for each metric, on the axes
        for patch in patches:
            axarr[k].add_patch(patch)

        # Title of the plot. Facultative, requires info about session (see RA
        # Info Chapter). We set the title only on the first raw of plots
#         if rtype == 'cpu':
# #             axarr[k][i].set_title('%s Tasks - %s Nodes' % (ss[sid]['ntask'],
# #                     int(ss[sid]['nnodes'])))
#             axarr[k].set_title('%s Tasks - %s Nodes' % (ss[sid]['ntask'],
#                     16))

        # Format axes
#         axarr[k][i].set_xlim([x['min'],     x['max']])
#         axarr[k].set_xlim([0,     2000])
#         if i == 0:
#         axarr[k].set_xlim([0,     1800])
#         if i == 1:
#        axarr[k].set_xlim([0,     1400])
        axarr[k].set_xlim([0,     300])

        axarr[k].set_ylim([y['min'], int(y['max'])])
#         axarr[k][i].set_ylim([0, 680])
        print('work-flow run-time (%s, %s): %f' % (str(k), str(i), x['max']))
        axarr[k].yaxis.set_major_locator(mticker.MaxNLocator(5))
        axarr[k].xaxis.set_major_locator(mticker.MaxNLocator(7))
        axarr[k].tick_params(axis='x', labelsize=8)
        axarr[k].tick_params(axis='y', labelsize=8)

#         axarr[k].set_xticklabels(['0', '300', '900', '1200', '1500', '1800']) # ddmd-seq
#         axarr[k].set_xticklabels(['0', '300', '900', '1200', '1500', '1800']) # ddmd-async

        for axis in ['top','bottom','left','right']:
            axarr[k].spines[axis].set_linewidth(0.5)
        axarr[k].tick_params(width=0.5)

        if rtype == 'cpu':
            # Specific to Summit when using SMT=4 (default)
            axarr[k].yaxis.set_major_formatter(
                    mticker.FuncFormatter(lambda z, pos: int(z/4)))
#             axarr[k][i].set_ylabel('CPU\nCores', fontsize=6, labelpad=4)

        # plot axis labels
        if k == 0: #and (i == 0 or i==2):
            axarr[k].set_ylabel('CPU Cores', fontsize=10, labelpad=3)
        if k == 1: #and (i == 0 or i==2):
            axarr[k].set_ylabel('GPUs', fontsize=10, labelpad=6)

        # Set x labels to letters for references in the paper.
        # Set them only for the bottom-most subplot
#         if rtype == 'gpu':
#             axarr[k][i].set_xlabel('(%s)' % j, labelpad=10)
#             if k == 1 and i == 0:
#             axarr[k][i].set_ylabel('GPUs', fontsize=6, labelpad=7)
        if k == 1:
            axarr[k].set_xlabel('Total Time to Execution [s]', fontsize=10, labelpad=4)

        # update session id and raw identifier letter
        j = chr(ord(j) + 1)
        break

# Add legend
# fig.legend(legend, [m[0] for m in metrics],
#            loc='upper center', bbox_to_anchor=(0.5, 1.25), ncol=6)

# Add axes labels
# fig.text(0.22, -0.15, 'Workflow Run-Time [s]', fontsize=6)
# fig.text(0.63, -0.15, 'Workflow Run-Time [s]', fontsize=6)
fig.savefig('Filtered.pdf', bbox_inches="tight")
andre-merzky commented 8 months ago

Hey @okilic1 - that is a different issue than what is covered in this one, so you may want to open a new ticket. But either way, please try https://github.com/radical-cybertools/radical.analytics/pull/184 which should address that problem.

okilic1 commented 8 months ago

I tested the filtering works. I will open a new ticket for #184