It was working fine when I first ran it. It stopped working even though I didn’t make any changes. The page shows “updating…” message and stays there. My graphics won’t load. When I run the graphics separately, it works.
app = Dash(__name__,external_stylesheets=['https://codepen.io/chriddyp/pen/bWLwgP.css'])
class results_graph():
def __init__(self) -> None:
self.app = app
async def run_server(self):
self.app.run_server(
port='7744',
debug=False,
)
async def plot_history(self,res: Result, properties=None, parameters: dict = None, path=None, now=None):
data = {}
selected_induvidual = {}
selected_location = ""
if res:
for i, obj in enumerate(properties._objectivies):
data[obj] = res.F[:, i]
for i, constr in enumerate(list(properties.equality_constraints_functions.keys())):
data[constr] = res.G[:, i]
for i, parameters_ in enumerate(parameters.keys()):
data[parameters_] = res.X[:, i]
df = pd.DataFrame(
data=data,
)
path = path.replace("\\", "/")
try:
df.to_json(
path+f"/results/pareto.json",
)
except Exception as e:
print(e)
pass
df["location"] = ["pymoo"] * len(df)
df["bw"] *= properties.normalizators_values["bw"]
df["gain"] *= properties.normalizators_values["gain"]
else:
df = pd.DataFrame({"loading": [0], "location": ["pymoo"]})
# f = px.scatter(
# df,
# x=properties.objectivies[0],
# y=properties.objectivies[1],
# color="location",
# hover_data=list(df.columns)
# )
styles = {
'pre': {
'border': 'thin lightgrey solid',
'overflowX': 'scroll'
}
}
fig = px.scatter(df, x="bw", y="gain", hover_data=list(
data.keys()), custom_data=[i for i in df.columns])
fig.update_layout(clickmode='event+select')
fig.update_traces(marker_size=20)
fig.show()
self.app.layout = html.Div([
dcc.Graph(
id='basic-interactions',
figure=fig
),
html.Div(className='column', children=[
html.Div([
dcc.Markdown("""
**Selection Data**
Choose the lasso or rectangle tool in the graph's menu
bar and then select points in the graph.
Note that if `layout.clickmode = 'event+select'`, selection data also
accumulates (or un-accumulates) selected data if you hold down the shift
button while clicking.
"""),
html.Pre(id='selected-data', style=styles['pre']),
], className='columns'),
]),
html.Div(className='columns', id="values", children=[
html.Div(className='columns', children=[
html.Div(className='column', children=[
html.H5(_, id=f"out{_}")
]),
html.Div(className='column', children=[
dcc.Input(
id="input_{}".format(_),
type="number",
placeholder="input type {}".format(_),
)
]),
]) for _ in data.keys()
]),
html.Div(
[
html.P(id="paragraph_id", children=["Button not clicked"]),
]
),
html.Button(id="button_id", children="Run Job!"),
html.Button(id="cosmos", children="Cosmos"),
html.Div(className='columns', children=[
html.Div([
dcc.Markdown("""
**Simulation Result**
"""),
html.Pre(id='simulation-result', style=styles['pre']),
], className='columns'),
]),
html.Div(className='columns', id="out" ),
html.Div(className='rows', id="cosmos-res" )
])
@app.callback(
Output(f"out", "children"),
*[Input(f"input_{_}", "value") for _ in parameters.keys()],
)
def update_inputs(*args, **kwargs):
if not all(args):
return args
print(args, "\n", kwargs)
selected_induvidual.update(
{key: value for key, value in zip(parameters.keys(), args)})
return args
@app.callback(
Output('selected-data', 'children'),
Output('values', 'children'),
Input('basic-interactions', 'selectedData'))
def display_selected_data(selectedData):
if selectedData is None:
return None , None
data_ = {}
for k in zip(selectedData["points"][0]["customdata"], data.keys()):
if k[1] in list(parameters.keys()):
data_[k[1]] = k[0]
selected_induvidual.update(data_)
com = [
html.Div(className='row', children=[
html.Div(className='column', children=[
html.H5(key, id=f"out{key}")
]),
html.Div(className='column', children=[
dcc.Input(
id="input_{}".format(key),
type="number",
placeholder="input type {}".format(key),
value=f"{value}",
)
]),
]) for key, value in data_.items()
]
return json.dumps(selectedData, indent=2), com
hspice = None
@app.callback(
Output("paragraph_id", "children"),
Output("simulation-result", "children"),
Output("basic-interactions", "figure"),
Input("button_id", "n_clicks"),
# TODO input values like [Input(f"input_{_}", "value") for _ in parameters.keys()]
)
def callback(n_clicks):
if n_clicks is None:
return "Button not clicked", None, None
total = 10
# for i in range(total):
# time.sleep(0.5)
#
def run_simulation():
os.makedirs(path+f"\\graphs", exist_ok=True)
os.makedirs(
path+f"\\graphs\\{now}_{properties.name}", exist_ok=True)
output_path = path+f"\\graphs\\{now}_{properties.name}"
os.makedirs(output_path+"\\out", exist_ok=True)
shutil.copy(path+"\\inputs\\130nm.txt", output_path+"\\130nm.txt")
shutil.copy(path+f"\\inputs\\{properties.sp_name}.sp",
output_path+f"\\{properties.sp_name}.sp")
shutil.copy(path+f"\\inputs\\{properties.param_name}.cir",
output_path+f"\\{properties.param_name}.cir")
h = HSpicePy(file_name=properties.sp_name,
design_file_name=properties.param_name, path=output_path, timeout="")
h.runner = True
h.change_parameters_to_cir(
**selected_induvidual,)
h.run_subporcess()
nonlocal hspice
hspice = h
return h
# import nest_asyncio
# nest_asyncio.apply()
# loop = asyncio.get_run()
# h_ = loop.run_until_complete(run_simulation())
h_ = run_simulation()
if not selected_induvidual.get("location", None):
r = h_.result.copy()
res = {obj: float(r[obj]) for obj in properties.objectivies}
res.update(
{param: float(value )for param, value in selected_induvidual.items()}
)
res["location"] = "user"
nonlocal df
df = df.append(res,ignore_index=True)
print(df)
fig = px.scatter(df, x="bw", y="gain", hover_data=df.columns,color = "location", custom_data=[i for i in df.columns])
fig.update_layout(clickmode='event+select')
fig.update_traces(marker_size=20)
return [f"Clicked {1} times"], json.dumps(h_.result, indent=2) , fig
@app.callback(
Output("cosmos-res", "children"),
Input("cosmos", "n_clicks"),
)
def callback(n_clicks):
if n_clicks is None or hspice is None:
return None
else:
hspice.open_cosmos()
reurn "Cosmos"