-
Notifications
You must be signed in to change notification settings - Fork 1
/
line_search.py
executable file
·130 lines (102 loc) · 3.69 KB
/
line_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import streamlit as st
import os
import json
import subprocess
def init_state():
# required for preparing context switching
st.session_state.current = 'linesearch'
st.session_state.linesearch = True
##########################################
# Variable initializations
st.session_state.variables_size = 2
st.session_state.phi = 45
st.session_state.theta = -120
def linesearch():
st.title("Introduzca los datos necesarios para su cómputo")
if not "linesearch" in st.session_state:
init_state()
sz, *var_sections = st.columns(st.session_state['variables_size'] + 1)
with sz:
var_cant = st.number_input(
"Cantidad de variables",
key="variables_size",
min_value=2,
max_value=2,
step=1,
help="varaiables de su ecuación no lineal"
)
var_names = [section.text_input("", key=f"key-x{i}") for i, section in enumerate(var_sections)]
form = st.text_input("Fórmula", help=
'Una expresión matemática.'
'Los operadores soportados son:'
'+, -, *, **, \\, ^, &, ...'
)
contr_cant = st.number_input(
"Cantidad de condiciones",
value=0,
min_value=0,
step=1,
help="condiciones que cumple su ecuación no lineal"
)
constrains = []
if contr_cant:
var_sections = []
for x in range(0, contr_cant, 4):
var_sections.extend(st.columns(min(4, contr_cant - x)))
for i, section in enumerate(var_sections):
with section:
st.latex(r"r_{%d}\\[-100pt]" % (i))
constrains.append(st.text_input("", key=f"key_r{i}"))
st.latex(r"\text{Punto inicial:}")
initial_p = st.columns(2)
x0 = initial_p[0].number_input("X")
y1 = initial_p[1].number_input("Y")
st.latex(r"\text{Intervalo a graficar en el eje X:}")
x_axis = st.columns(2)
u0 = x_axis[0].number_input("inicio", key="x0")
u1 = x_axis[1].number_input("fin", key="x1")
st.latex(r"\text{Intervalo a graficar en el eje Y:}")
y_axis = st.columns(2)
v0 = y_axis[0].number_input("inicio", key="y0")
v1 = y_axis[1].number_input("fin", key="y1")
st.latex(r"\text{Ángulo de inclinación de la cámara:}")
col = st.columns(2)
phi = col[0].number_input(
"Phi",
value=st.session_state.phi,
help="Camera phi",
)
theta = col[1].number_input(
"theta",
value=st.session_state.theta,
help="Camera theta",
)
run = st.button("Computar")
if run:
placeholder = st.empty() # For displaying messages
placeholder.success("Ejecutando...")
data = {
"vars": [v for v in var_names],
"func": form,
"constraints": constrains,
"initial_point": [x0, y1],
"x_range": [u0, u1],
"y_range": [v0, v1],
"camera_phi": phi,
"camera_theta": theta
}
json_object = json.dumps(data, indent = 4)
path = os.path.abspath(os.path.join(__file__, "../../src/line_search/model_ls.json"))
with open(path, "w") as outfile:
outfile.write(json_object)
# Execute Manim graphics
subprocess.run(["manim", "-ql", "main.py", "LineSearch"])
video_path = "media/videos/main/480p15/LineSearch.mp4"
# clear the placeholder at the end
placeholder.empty()
try:
st.video(video_path)
except FileNotFoundError:
st.write('Whoops, something went wront, check the streamlit console for more details')
# clear the placeholder at the end
placeholder.empty()