Spaces:
Sleeping
Sleeping
adds normalized variables on update
Browse filesFiles changed (3)
252 unmodified lines253254255256257258259260261262263264265266267268269270271252 unmodified linesinc_params = _parse_json_field(incoming.get('parameters'), {})inc_artifacts = _parse_json_field(incoming.get('artifacts'), [])inc_logs = _parse_json_field(incoming.get('logs'), [])# Merge metrics with de-dupmerged_metrics = []seen = set()for entry in base_metrics + inc_metrics:try:# Use the original entry so _metrics_key can properly# distinguish dict vs non-dict entrieskey = _metrics_key(entry)except Exception:key = (None, None)if key not in seen:seen.add(key)merged_metrics.append(entry)# Merge paramsmerged_params = {}if isinstance(base_params, dict):252 unmodified lines253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310252 unmodified linesinc_params = _parse_json_field(incoming.get('parameters'), {})inc_artifacts = _parse_json_field(incoming.get('artifacts'), [])inc_logs = _parse_json_field(incoming.get('logs'), [])# Merge metrics with de-dup (by step+timestamp) then collapse per stepmerged_metrics = []seen = set()for entry in base_metrics + inc_metrics:try:key = _metrics_key(entry)except Exception:key = (None, None)if key not in seen:seen.add(key)merged_metrics.append(entry)# Collapse duplicate steps by merging their metric dicts and keeping the latest timestamptry:step_to_entry: Dict[Any, Dict[str, Any]] = {}for e in merged_metrics:if not isinstance(e, dict):continue# Ensure nested structure {timestamp, step, metrics}if 'metrics' not in e:e = {'timestamp': e.get('timestamp'),'step': e.get('step'),'metrics': {k: v for k, v in e.items() if k not in ('step', 'timestamp')}}step_val = e.get('step')if step_val in step_to_entry:existing_e = step_to_entry[step_val]try:existing_metrics_dict = existing_e.get('metrics', {})if isinstance(existing_metrics_dict, dict):existing_metrics_dict.update(e.get('metrics', {}))else:existing_e['metrics'] = e.get('metrics', {})except Exception:existing_e['metrics'] = e.get('metrics', {})try:if str(e.get('timestamp', '')) > str(existing_e.get('timestamp', '')):existing_e['timestamp'] = e.get('timestamp')except Exception:passelse:step_to_entry[step_val] = dict(e)def _step_key(x: Dict[str, Any]):try:return float(x.get('step'))except Exception:return -1.0merged_metrics = sorted(step_to_entry.values(), key=_step_key)except Exception:# On any error, keep the de-duplicated listpass# Merge paramsmerged_params = {}if isinstance(base_params, dict):
309 unmodified lines310311312313314315309 unmodified linesexcept Exception:pass# Merge artifacts if providedif 'artifacts' in experiment_data and isinstance(experiment_data['artifacts'], list):# De-duplicate while preserving order309 unmodified lines310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363309 unmodified linesexcept Exception:pass# Collapse duplicate step entries by merging their metric dictionariestry:def _collapse_by_step(entries: list) -> list:step_to_entry: dict = {}for e in entries:if not isinstance(e, dict):continue# Normalize to nested structureif 'metrics' not in e:e = {'timestamp': e.get('timestamp'),'step': e.get('step'),'metrics': {k: v for k, v in e.items() if k not in ('step', 'timestamp')}}step_val = e.get('step')if step_val in step_to_entry:# Merge metrics into existing entry for the same stepexisting_e = step_to_entry[step_val]try:existing_e_metrics = existing_e.get('metrics', {})if isinstance(existing_e_metrics, dict):existing_e_metrics.update(e.get('metrics', {}))else:existing_e['metrics'] = e.get('metrics', {})except Exception:existing_e['metrics'] = e.get('metrics', {})# Prefer the latest timestamp (ISO strings compare lexicographically)try:if str(e.get('timestamp', '')) > str(existing_e.get('timestamp', '')):existing_e['timestamp'] = e.get('timestamp')except Exception:passelse:step_to_entry[step_val] = dict(e)# Sort by step (fallback to 0 for None/non-numeric)def _step_key(x):val = x.get('step')try:return float(val)except Exception:return -1.0return sorted(step_to_entry.values(), key=_step_key)merged_metrics = _collapse_by_step(merged_metrics)except Exception:# If anything goes wrong, keep original listpass# Merge artifacts if providedif 'artifacts' in experiment_data and isinstance(experiment_data['artifacts'], list):# De-duplicate while preserving order
660 unmodified lines661662663664665666667668669670671672673674675676677678660 unmodified linesif not experiment['metrics']:return pd.DataFrame()# Convert metrics to DataFramedata = []for metric_entry in experiment['metrics']:step = metric_entry.get('step', 0)timestamp = metric_entry.get('timestamp', '')metrics = metric_entry.get('metrics', {})row = {'step': step, 'timestamp': timestamp}row.update(metrics)data.append(row)return pd.DataFrame(data)# Global instancetrackio_space = TrackioSpace()660 unmodified lines661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692660 unmodified linesif not experiment['metrics']:return pd.DataFrame()# Convert metrics to DataFrame (merge duplicate steps)data = []for metric_entry in experiment['metrics']:step = metric_entry.get('step', 0)timestamp = metric_entry.get('timestamp', '')metrics = metric_entry.get('metrics', {})row = {'step': step, 'timestamp': timestamp}row.update(metrics)data.append(row)if not data:return pd.DataFrame()df = pd.DataFrame(data)# Ensure step exists even if Noneif 'step' not in df.columns:df['step'] = 0# For duplicate steps, keep the latest timestamp and merge columns by last valid valuetry:df.sort_values(['step', 'timestamp'], inplace=True)# Take the last row per step (latest timestamp)df = df.groupby('step', as_index=False).last()except Exception:passreturn df# Global instancetrackio_space = TrackioSpace()
src/dataset_utils.py+42-3
src/monitoring.py+48
templates/spaces/trackio/app.py+18-4