componavt commited on
Commit
e3446a9
·
1 Parent(s): 79ecbf5

works well 04

Browse files
Files changed (2) hide show
  1. app.py +198 -13
  2. gitingest.sh +1 -1
app.py CHANGED
@@ -55,6 +55,41 @@ DEFAULTS = {
55
  DEFAULT_PARAMS_TEXT = parameters_to_text(DEFAULTS)
56
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  def run_simulation(
59
  t_number: int,
60
  t_train_end: float,
@@ -150,12 +185,13 @@ def run_simulation(
150
  t_train_end, t_full_end, t_number
151
  )
152
 
153
- shadowing_fig = None
154
- if show_connections:
155
- shadowing_fig = make_shadowing_figure(
156
- solutions, selected_indices, solver_type,
157
- t_train_end, t_full_end, t_number, rhs_func
158
- )
 
159
 
160
  diagnostics.append("Step 9: Creating metrics table...")
161
 
@@ -385,6 +421,8 @@ def build_trajectory_choices(df_metrics: pd.DataFrame, top_n: int = 5):
385
  with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
386
  gr.Markdown("# Differ Hug: ODE Research Platform")
387
  gr.Markdown("Interactive Gene Regulatory ODE System")
 
 
388
 
389
  with gr.Row():
390
  with gr.Column(scale=1):
@@ -428,8 +466,9 @@ with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
428
  value=DEFAULTS["solver_type"]
429
  )
430
  show_connections = gr.Checkbox(
431
- label="Show shadowing analysis (trajectory vs. perturbed trajectory)",
432
- value=False
 
433
  )
434
  connection_stride = gr.Slider(
435
  label="Connection stride", minimum=1, maximum=20, step=1,
@@ -443,7 +482,7 @@ with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
443
  interactive=True
444
  )
445
 
446
- run_button = gr.Button("Run Simulation", variant="primary")
447
 
448
  gr.Markdown("### Plain Text Parameters")
449
  params_text = gr.Textbox(
@@ -482,8 +521,9 @@ with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
482
  gr.Markdown("- Top 5 anomalous trajectories are selected by default")
483
 
484
  run_button.click(
485
- fn=run_simulation,
486
  inputs=[
 
487
  t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
488
  initial_radius, num_points, circle_start, circle_end,
489
  center_x, center_y, solver_type, show_connections, connection_stride,
@@ -495,7 +535,29 @@ with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
495
  ]
496
  )
497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
498
  apply_text_btn.click(
 
 
 
 
499
  fn=apply_text_to_controls,
500
  inputs=[
501
  params_text, t_number, t_train_end, t_full_end, alpha, K, b,
@@ -508,6 +570,14 @@ with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
508
  circle_start, circle_end, center_x, center_y, solver_type,
509
  params_text, selected_indices
510
  ]
 
 
 
 
 
 
 
 
511
  )
512
 
513
  read_text_btn.click(
@@ -521,9 +591,123 @@ with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
521
  )
522
 
523
  num_points.change(
524
- fn=update_selected_indices,
525
- inputs=[num_points],
526
- outputs=selected_indices
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
527
  )
528
 
529
  demo.load(
@@ -549,4 +733,5 @@ with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
549
  )
550
 
551
  if __name__ == "__main__":
 
552
  demo.launch(server_name="0.0.0.0", server_port=7860, share=False, show_error=True)
 
55
  DEFAULT_PARAMS_TEXT = parameters_to_text(DEFAULTS)
56
 
57
 
58
+ def guarded_run_simulation(
59
+ is_batch_update,
60
+ t_number: int,
61
+ t_train_end: float,
62
+ t_full_end: float,
63
+ alpha: float,
64
+ K: float,
65
+ b: float,
66
+ gamma1: float,
67
+ gamma2: float,
68
+ initial_radius: float,
69
+ num_points: int,
70
+ circle_start: int,
71
+ circle_end: int,
72
+ center_x: float,
73
+ center_y: float,
74
+ solver_type: str,
75
+ show_connections: bool,
76
+ connection_stride: int,
77
+ selected_indices: list,
78
+ ) -> Tuple[Any, Any, Any, Any, Any, str, str, str, Any]:
79
+ """
80
+ Guarded version of run_simulation that skips computation when is_batch_update is True.
81
+ """
82
+ if is_batch_update:
83
+ return tuple(gr.update() for _ in range(9))
84
+ return run_simulation(
85
+ t_number, t_train_end, t_full_end,
86
+ alpha, K, b, gamma1, gamma2,
87
+ initial_radius, num_points, circle_start, circle_end,
88
+ center_x, center_y, solver_type, show_connections, connection_stride,
89
+ selected_indices
90
+ )
91
+
92
+
93
  def run_simulation(
94
  t_number: int,
95
  t_train_end: float,
 
185
  t_train_end, t_full_end, t_number
186
  )
187
 
188
+ shadowing_fig = make_shadowing_figure(
189
+ solutions, selected_indices, solver_type,
190
+ t_train_end, t_full_end, t_number, rhs_func
191
+ )
192
+
193
+ if rhs_func is None:
194
+ diagnostics.append("WARNING: rhs_func is None, shadowing figure will use zero vector field as fallback (reduced accuracy)")
195
 
196
  diagnostics.append("Step 9: Creating metrics table...")
197
 
 
421
  with gr.Blocks(title="Differ Hug: ODE Research Platform") as demo:
422
  gr.Markdown("# Differ Hug: ODE Research Platform")
423
  gr.Markdown("Interactive Gene Regulatory ODE System")
424
+
425
+ is_batch_update = gr.State(value=False)
426
 
427
  with gr.Row():
428
  with gr.Column(scale=1):
 
466
  value=DEFAULTS["solver_type"]
467
  )
468
  show_connections = gr.Checkbox(
469
+ label="Show DOP853 ↔ NN connection lines on phase portrait",
470
+ value=False,
471
+ info="Controls whether connection lines between DOP853 and NN trajectories are shown on the phase portrait. This does not affect the Shadowing tab."
472
  )
473
  connection_stride = gr.Slider(
474
  label="Connection stride", minimum=1, maximum=20, step=1,
 
482
  interactive=True
483
  )
484
 
485
+ run_button = gr.Button("Recompute now", variant="secondary")
486
 
487
  gr.Markdown("### Plain Text Parameters")
488
  params_text = gr.Textbox(
 
521
  gr.Markdown("- Top 5 anomalous trajectories are selected by default")
522
 
523
  run_button.click(
524
+ fn=guarded_run_simulation,
525
  inputs=[
526
+ is_batch_update,
527
  t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
528
  initial_radius, num_points, circle_start, circle_end,
529
  center_x, center_y, solver_type, show_connections, connection_stride,
 
535
  ]
536
  )
537
 
538
+ sim_inputs = [
539
+ t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
540
+ initial_radius, num_points, circle_start, circle_end,
541
+ center_x, center_y, solver_type, show_connections, connection_stride,
542
+ selected_indices
543
+ ]
544
+ sim_outputs = [
545
+ phase_fig, time_fig, shadowing_fig, metrics_table, metrics_csv_file,
546
+ diagnostics_text, params_text, latex_eq, selected_indices
547
+ ]
548
+
549
+ for comp in sim_inputs:
550
+ comp.change(
551
+ fn=guarded_run_simulation,
552
+ inputs=[is_batch_update] + sim_inputs,
553
+ outputs=sim_outputs
554
+ )
555
+
556
  apply_text_btn.click(
557
+ fn=lambda: True,
558
+ inputs=[],
559
+ outputs=[is_batch_update]
560
+ ).then(
561
  fn=apply_text_to_controls,
562
  inputs=[
563
  params_text, t_number, t_train_end, t_full_end, alpha, K, b,
 
570
  circle_start, circle_end, center_x, center_y, solver_type,
571
  params_text, selected_indices
572
  ]
573
+ ).then(
574
+ fn=lambda: False,
575
+ inputs=[],
576
+ outputs=[is_batch_update]
577
+ ).then(
578
+ fn=run_simulation,
579
+ inputs=sim_inputs,
580
+ outputs=sim_outputs
581
  )
582
 
583
  read_text_btn.click(
 
591
  )
592
 
593
  num_points.change(
594
+ fn=guarded_run_simulation,
595
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
596
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
597
+ show_connections, connection_stride, selected_indices],
598
+ outputs=sim_outputs
599
+ )
600
+ t_train_end.change(
601
+ fn=guarded_run_simulation,
602
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
603
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
604
+ show_connections, connection_stride, selected_indices],
605
+ outputs=sim_outputs
606
+ )
607
+ t_full_end.change(
608
+ fn=guarded_run_simulation,
609
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
610
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
611
+ show_connections, connection_stride, selected_indices],
612
+ outputs=sim_outputs
613
+ )
614
+ alpha.change(
615
+ fn=guarded_run_simulation,
616
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
617
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
618
+ show_connections, connection_stride, selected_indices],
619
+ outputs=sim_outputs
620
+ )
621
+ K.change(
622
+ fn=guarded_run_simulation,
623
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
624
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
625
+ show_connections, connection_stride, selected_indices],
626
+ outputs=sim_outputs
627
+ )
628
+ b.change(
629
+ fn=guarded_run_simulation,
630
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
631
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
632
+ show_connections, connection_stride, selected_indices],
633
+ outputs=sim_outputs
634
+ )
635
+ gamma1.change(
636
+ fn=guarded_run_simulation,
637
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
638
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
639
+ show_connections, connection_stride, selected_indices],
640
+ outputs=sim_outputs
641
+ )
642
+ gamma2.change(
643
+ fn=guarded_run_simulation,
644
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
645
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
646
+ show_connections, connection_stride, selected_indices],
647
+ outputs=sim_outputs
648
+ )
649
+ initial_radius.change(
650
+ fn=guarded_run_simulation,
651
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
652
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
653
+ show_connections, connection_stride, selected_indices],
654
+ outputs=sim_outputs
655
+ )
656
+ circle_start.change(
657
+ fn=guarded_run_simulation,
658
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
659
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
660
+ show_connections, connection_stride, selected_indices],
661
+ outputs=sim_outputs
662
+ )
663
+ circle_end.change(
664
+ fn=guarded_run_simulation,
665
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
666
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
667
+ show_connections, connection_stride, selected_indices],
668
+ outputs=sim_outputs
669
+ )
670
+ center_x.change(
671
+ fn=guarded_run_simulation,
672
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
673
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
674
+ show_connections, connection_stride, selected_indices],
675
+ outputs=sim_outputs
676
+ )
677
+ center_y.change(
678
+ fn=guarded_run_simulation,
679
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
680
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
681
+ show_connections, connection_stride, selected_indices],
682
+ outputs=sim_outputs
683
+ )
684
+ solver_type.change(
685
+ fn=guarded_run_simulation,
686
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
687
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
688
+ show_connections, connection_stride, selected_indices],
689
+ outputs=sim_outputs
690
+ )
691
+ show_connections.change(
692
+ fn=guarded_run_simulation,
693
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
694
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
695
+ show_connections, connection_stride, selected_indices],
696
+ outputs=sim_outputs
697
+ )
698
+ connection_stride.change(
699
+ fn=guarded_run_simulation,
700
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
701
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
702
+ show_connections, connection_stride, selected_indices],
703
+ outputs=sim_outputs
704
+ )
705
+ selected_indices.change(
706
+ fn=guarded_run_simulation,
707
+ inputs=[is_batch_update, t_number, t_train_end, t_full_end, alpha, K, b, gamma1, gamma2,
708
+ initial_radius, num_points, circle_start, circle_end, center_x, center_y, solver_type,
709
+ show_connections, connection_stride, selected_indices],
710
+ outputs=sim_outputs
711
  )
712
 
713
  demo.load(
 
733
  )
734
 
735
  if __name__ == "__main__":
736
+ demo.queue(default_concurrency_limit=1, max_size=20)
737
  demo.launch(server_name="0.0.0.0", server_port=7860, share=False, show_error=True)
gitingest.sh CHANGED
@@ -6,4 +6,4 @@ gitingest . \
6
  --include-pattern "requirements.txt" \
7
  --exclude-pattern "LICENSE" \
8
  --exclude-pattern "*/__pycache__/*" \
9
- --output out_gitingest/differ_hug_01.txt
 
6
  --include-pattern "requirements.txt" \
7
  --exclude-pattern "LICENSE" \
8
  --exclude-pattern "*/__pycache__/*" \
9
+ --output out_gitingest/differ_hug_04_works.txt