Skip to content

Commit

Permalink
Merge pull request #623 from SRI-International/master
Browse files Browse the repository at this point in the history
Merge latest from master into observables-work
  • Loading branch information
rtvuser1 authored Sep 27, 2024
2 parents 6d6d461 + 56bad0c commit 725187c
Show file tree
Hide file tree
Showing 5 changed files with 1,539 additions and 7 deletions.
44 changes: 40 additions & 4 deletions _common/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
# Option to save metrics to data file
save_metrics = True

# Option to merge new group metrics into existing
merge_group_metrics = False

# Suffix to append to filename of DATA- files
data_suffix = ""

Expand Down Expand Up @@ -2824,11 +2827,18 @@ def store_app_metrics (backend_id, circuit_metrics, group_metrics, app, start_ti
if app not in shared_data:
shared_data[app] = { "circuit_metrics":None, "group_metrics":None }

shared_data[app]["backend_id"] = backend_id
shared_data[app]["start_time"] = start_time
shared_data[app]["end_time"] = end_time
# if merging data, merge the new data into the existing group metrics
if merge_group_metrics:
#merged_metrics = do_merge_group_metrics(existing_metrics, new_metrics)
shared_data[app]["group_metrics"] = do_merge_group_metrics(shared_data[app]["group_metrics"], group_metrics)

shared_data[app]["group_metrics"] = group_metrics
# otherwise overwrite (the default mode)
else:
shared_data[app]["backend_id"] = backend_id
shared_data[app]["start_time"] = start_time
shared_data[app]["end_time"] = end_time

shared_data[app]["group_metrics"] = group_metrics

# if saving raw circuit data, add it too
#shared_data[app]["circuit_metrics"] = circuit_metrics
Expand Down Expand Up @@ -2899,7 +2909,33 @@ def load_app_metrics (api, backend_id):
#print(group_metrics)

return shared_data

# Merge a new set of metrics into the existing set
def do_merge_group_metrics(existing_metrics, new_metrics):

# Create a dictionary to map groups to their index in the existing metrics
group_index_map = {group: idx for idx, group in enumerate(existing_metrics['groups'])}

# Iterate through the new metrics
for idx, group in enumerate(new_metrics['groups']):
if group in group_index_map:
# If the group exists, update its metrics
existing_idx = group_index_map[group]
for key in existing_metrics:
if key != 'groups':
existing_metrics[key][existing_idx] = new_metrics[key][idx]
else:
# If the group doesn't exist, add it to the existing metrics
existing_metrics['groups'].append(group)
for key in existing_metrics:
if key != 'groups':
existing_metrics[key].append(new_metrics[key][idx])

# Update the group_index_map
group_index_map[group] = len(existing_metrics['groups']) - 1

return existing_metrics


##############################################
# VOLUMETRIC PLOT
Expand Down
Loading

0 comments on commit 725187c

Please sign in to comment.