Skip to content

Commit fc95f07

Browse files
gescholtclaude
andcommitted
feat: improve lv4d workflow with colors and parameter queries
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent dc5e5ef commit fc95f07

1 file changed

Lines changed: 143 additions & 41 deletions

File tree

scripts/lv4d_repl_workflow.jl

Lines changed: 143 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,59 @@ This provides:
1212
- remove_failed!(): Remove all failed experiments
1313
- analyze_lv4d(path): Quick single-experiment analysis
1414
- analyze_lv4d(1): Analyze by index
15+
- find_by_params(GN=16): Filter experiments by parameters
16+
- coverage(): Show parameter coverage matrix
1517
=#
1618

19+
# ============================================================================
20+
# ANSI Terminal Colors (matching TUI patterns)
21+
# ============================================================================
22+
23+
const CYAN = "\e[36m"
24+
const YELLOW = "\e[33m"
25+
const GREEN = "\e[32m"
26+
const RED = "\e[31m"
27+
const DIM = "\e[2m"
28+
const BOLD = "\e[1m"
29+
const RESET = "\e[0m"
30+
31+
# Status helpers
32+
_success(msg) = println("$(GREEN)$(RESET) $msg")
33+
_warning(msg) = println("$(YELLOW)$(RESET) $msg")
34+
_info(msg) = println("$(DIM)$msg$(RESET)")
35+
_error(msg) = println("$(RED)$(RESET) $msg")
36+
37+
# ============================================================================
38+
# Package Loading (quiet)
39+
# ============================================================================
40+
1741
using Pkg
18-
Pkg.activate(joinpath(@__DIR__, ".."))
42+
redirect_stderr(devnull) do
43+
Pkg.activate(joinpath(@__DIR__, ".."), io=devnull)
44+
end
1945
using GlobtimPostProcessing
2046
using GlobtimPostProcessing.Pipeline
2147
using GlobtimPostProcessing.Pipeline: DISCOVERED, ANALYZING, ANALYZED, FAILED
48+
using GlobtimPostProcessing.Pipeline: get_experiments_by_params, get_parameter_coverage, print_coverage_matrix
2249
using GlobtimPostProcessing.LV4DAnalysis
2350
using DataFrames
51+
using PrettyTables
52+
using Printf
2453

2554
# ============================================================================
2655
# Registry Setup
2756
# ============================================================================
2857

29-
println("Loading registry...")
3058
if !@isdefined(registry) || !isa(registry, PipelineRegistry)
3159
global registry = load_pipeline_registry()
3260
else
33-
println(" (Using existing registry, call reload_registry!() to refresh)")
61+
_info("Using existing registry, call reload_registry!() to refresh")
3462
end
3563
n_new = scan_for_experiments!(registry)
3664
if n_new > 0
37-
println(" Discovered $n_new new experiments")
65+
_info("Discovered $n_new new experiments")
3866
save_pipeline_registry(registry)
3967
end
40-
println(" $(length(registry.experiments)) experiments loaded")
4168

4269
"""Reload the registry from disk"""
4370
function reload_registry!()
@@ -46,7 +73,7 @@ function reload_registry!()
4673
if n_new > 0
4774
save_pipeline_registry(registry)
4875
end
49-
println("Registry reloaded: $(length(registry.experiments)) experiments")
76+
_success("Registry reloaded: $(length(registry.experiments)) experiments")
5077
return registry
5178
end
5279

@@ -79,15 +106,56 @@ function remove_failed!(; save::Bool=true)
79106
failed = failed_experiments()
80107
for path in failed
81108
remove_experiment!(registry, path)
82-
println(" Removed: $(basename(path))")
109+
_info("Removed: $(basename(path))")
83110
end
84111
if save && !isempty(failed)
85112
save_pipeline_registry(registry)
86113
end
87-
println("Removed $(length(failed)) failed experiments")
114+
_success("Removed $(length(failed)) failed experiments")
88115
return failed
89116
end
90117

118+
# ============================================================================
119+
# Parameter Query Functions
120+
# ============================================================================
121+
122+
"""
123+
find_by_params(; GN=nothing, domain=nothing, deg_min=nothing, deg_max=nothing)
124+
125+
Filter experiments by parameters. Returns vector of experiment entries.
126+
127+
# Example
128+
```julia
129+
find_by_params(GN=16) # All GN=16 experiments
130+
find_by_params(GN=16, domain=0.08) # GN=16 with domain=0.08
131+
find_by_params(deg_min=4, deg_max=12) # Specific degree range
132+
```
133+
"""
134+
function find_by_params(; GN=nothing, domain=nothing, deg_min=nothing, deg_max=nothing)
135+
results = get_experiments_by_params(registry; GN, domain, deg_min, deg_max)
136+
if isempty(results)
137+
_warning("No experiments match the specified parameters")
138+
else
139+
_success("Found $(length(results)) matching experiments")
140+
end
141+
return results
142+
end
143+
144+
"""
145+
coverage()
146+
147+
Show parameter coverage matrix for all experiments in the registry.
148+
Displays a grid of GN × domain combinations with experiment counts.
149+
"""
150+
function coverage()
151+
cov = get_parameter_coverage(registry)
152+
println()
153+
println("$(BOLD)Parameter Coverage Matrix$(RESET)")
154+
println("$(DIM)─────────────────────────$(RESET)")
155+
print_coverage_matrix(cov)
156+
println()
157+
end
158+
91159
# ============================================================================
92160
# LV4D Analysis Shortcuts
93161
# ============================================================================
@@ -97,21 +165,21 @@ function analyze_lv4d(path::String; verbose::Bool=true)
97165
exp = load_experiment(path)
98166

99167
if verbose
100-
println("\n" * "="^60)
101-
println("Experiment: $(experiment_id(exp))")
102-
println("="^60)
168+
println()
169+
println("$(BOLD)$(CYAN)Experiment: $(experiment_id(exp))$(RESET)")
170+
println("$(DIM)" * ""^60 * "$(RESET)")
103171
println("Degrees: ", available_degrees(exp))
104172

105173
# Quality summary
106174
if has_critical_points(exp)
107175
cps = critical_points(exp)
108-
println("Critical points: ", nrow(cps))
176+
_success("$(nrow(cps)) critical points found")
109177
end
110178

111179
# Degree results
112180
dr = degree_results(exp)
113181
if dr !== nothing && !isempty(dr)
114-
println("\nDegree Results:")
182+
println("\n$(BOLD)Degree Results:$(RESET)")
115183
println(dr[:, [:degree, :L2_norm, :critical_points, :recovery_error]])
116184
end
117185
end
@@ -128,48 +196,82 @@ function analyze_lv4d(idx::Int; kwargs...)
128196
analyze_lv4d(paths[idx]; kwargs...)
129197
end
130198

131-
"""List LV4D experiments with indices"""
199+
"""
200+
list_lv4d(; limit::Int=20)
201+
202+
List LV4D experiments with indices in a formatted table.
203+
"""
132204
function list_lv4d(; limit::Int=20)
133205
paths = lv4d_experiments()
134-
println("\nLV4D Experiments ($(length(paths)) total):")
135-
println("-"^60)
136-
for (i, path) in enumerate(paths[1:min(limit, length(paths))])
206+
n = min(limit, length(paths))
207+
208+
if n == 0
209+
_warning("No LV4D experiments found")
210+
return
211+
end
212+
213+
# Build table data
214+
data = Matrix{Any}(undef, n, 5)
215+
for (i, path) in enumerate(paths[1:n])
137216
entry = registry.experiments[path]
138-
status_str = string(entry.status)
139-
params = entry.params
140-
if params !== nothing
141-
println(" $i. GN=$(params.GN), deg=$(params.deg_min)-$(params.deg_max), domain=$(params.domain) [$status_str]")
217+
p = entry.params
218+
data[i, 1] = i
219+
data[i, 2] = p === nothing ? "-" : p.GN
220+
data[i, 3] = p === nothing ? "-" : "$(p.deg_min)-$(p.deg_max)"
221+
data[i, 4] = p === nothing ? "-" : @sprintf("%.2e", p.domain)
222+
# Color status
223+
status = entry.status
224+
data[i, 5] = if status == ANALYZED
225+
"$(GREEN)analyzed$(RESET)"
226+
elseif status == FAILED
227+
"$(RED)failed$(RESET)"
228+
elseif status == ANALYZING
229+
"$(YELLOW)analyzing$(RESET)"
142230
else
143-
println(" $i. $(basename(path)) [$status_str]")
231+
"$(DIM)pending$(RESET)"
144232
end
145233
end
234+
235+
println()
236+
println("$(BOLD)LV4D Experiments$(RESET) $(DIM)($(length(paths)) total)$(RESET)")
237+
pretty_table(data,
238+
header = ["#", "GN", "Deg", "Domain", "Status"],
239+
alignment = [:r, :r, :c, :r, :l],
240+
tf = tf_unicode_rounded,
241+
show_subheader = false
242+
)
243+
146244
if length(paths) > limit
147-
println(" ... and $(length(paths) - limit) more")
245+
_info("$(length(paths) - limit) more experiments not shown (use limit=N to see more)")
148246
end
149247
end
150248

151249
# ============================================================================
152250
# Print Summary
153251
# ============================================================================
154252

155-
println("\n" * "="^60)
156-
println("LV4D Post-Processing Workflow Ready")
157-
println("="^60)
253+
println()
254+
println("$(BOLD)$(CYAN)LV4D Post-Processing Workflow$(RESET)")
255+
println("$(DIM)─────────────────────────────$(RESET)")
158256

159257
lv4d_paths = lv4d_experiments()
160-
failed = failed_experiments()
161-
analyzed = analyzed_experiments()
162-
discovered = discovered_experiments()
163-
println(" LV4D experiments: $(length(lv4d_paths))")
164-
println(" Status: $(length(analyzed)) analyzed, $(length(discovered)) pending, $(length(failed)) failed")
165-
166-
println("\nAvailable commands:")
167-
println(" lv4d_experiments() # List all LV4D experiment paths")
168-
println(" list_lv4d() # Show experiments with indices")
169-
println(" failed_experiments() # List failed experiments")
170-
println(" remove_failed!() # Remove all failed from registry")
171-
println(" analyze_lv4d(path) # Quick analysis of experiment")
172-
println(" analyze_lv4d(1) # Analyze by index")
173-
println(" reload_registry!() # Reload registry from disk")
174-
println(" lv4d() # Launch interactive TUI")
258+
n_analyzed = length(analyzed_experiments())
259+
n_pending = length(discovered_experiments())
260+
n_failed = length(failed_experiments())
261+
262+
_success("$(length(registry.experiments)) experiments in registry")
263+
println(" $(GREEN)$n_analyzed$(RESET) analyzed, $(YELLOW)$n_pending$(RESET) pending, $(RED)$n_failed$(RESET) failed")
264+
println(" $(DIM)$(length(lv4d_paths)) are LV4D experiments$(RESET)")
265+
266+
println()
267+
println("$(BOLD)Commands:$(RESET)")
268+
println(" $(CYAN)list_lv4d()$(RESET) Show experiments with indices")
269+
println(" $(CYAN)analyze_lv4d(1)$(RESET) Analyze by index")
270+
println(" $(CYAN)analyze_lv4d(path)$(RESET) Analyze by path")
271+
println(" $(CYAN)find_by_params(GN=16)$(RESET) Filter by parameters")
272+
println(" $(CYAN)coverage()$(RESET) Show parameter coverage matrix")
273+
println(" $(CYAN)failed_experiments()$(RESET) List failed experiments")
274+
println(" $(CYAN)remove_failed!()$(RESET) Remove all failed from registry")
275+
println(" $(CYAN)reload_registry!()$(RESET) Reload registry from disk")
276+
println(" $(CYAN)lv4d()$(RESET) Launch interactive TUI")
175277
println()

0 commit comments

Comments
 (0)