Commit 21bc3e3c authored by LIGNEUL CLEMENT's avatar LIGNEUL CLEMENT
Browse files

add 3d plots

parent 7c4feafd
......@@ -3,6 +3,8 @@ all:
@echo "\n##### Initialisation #####\n"
rm -rf deploy dist
npx nodegui-packer --init EASEA-compiler-app
@echo "\n##### Build de dist #####\n"
......@@ -13,9 +15,11 @@ all:
npx nodegui-packer --pack ./dist
@echo "\n##### Copie du script de graphe #####\n"
@echo "\n##### Copie des scripts de graphe #####\n"
find 'deploy/' -type d -name doc | sed 's/doc//' | xargs -n 1 cp -v src/scripts/plot.py
find 'deploy/' -type d -name doc | sed 's/doc//' | xargs -n 1 cp -v src/plot.py
find 'deploy/' -type d -name doc | sed 's/doc//' | xargs -n 1 cp -v src/3D_plot.py
@echo "\n##### Packaging terminé #####\n"
......
import plotly.express as px
import os
from pandas.io.parsers import read_csv
import plotly.express as px
import sys
if len(sys.argv) != 4:
print(
"Usage : " + sys.argv[0] + " <nb of generations> <nb of plots> <csv file>",
file=sys.stderr,
)
exit(1)
df = read_csv(
sys.argv[3], header=0, delimiter=" ", usecols=[0, 1, 2], names=["f1", "f2", "f3"]
)
fig = px.scatter_3d(
df, x="f1", y="f2", z="f3", color="f2", size="f3", size_max=18, opacity=0.7
)
# tight layout
fig.update_layout(margin=dict(l=0, r=0, b=0, t=0))
fig.write_html("plotting/fig.html")
fig.write_image("plotting/fig.svg", engine="kaleido", scale=2)
......@@ -74,12 +74,24 @@ export class Compile {
check_nsgaii.setText('nsgaii');
check_nsgaii.addEventListener('stateChanged', () => {
this.nsgaii = !this.nsgaii;
if (check_nsgaii.isChecked()) {
run_obj.nb_plot_box.text_edit.clear();
run_obj.nb_plot_box.widget.setEnabled(false);
} else {
run_obj.nb_plot_box.widget.setEnabled(true);
}
});
const check_nsgaiii = new QCheckBox();
check_nsgaiii.setText('nsgaiii');
check_nsgaiii.addEventListener('stateChanged', () => {
this.nsgaiii = !this.nsgaiii;
if (check_nsgaiii.isChecked()) {
run_obj.nb_plot_box.text_edit.clear();
run_obj.nb_plot_box.widget.setEnabled(false);
} else {
run_obj.nb_plot_box.widget.setEnabled(true);
}
});
const check_asrea = new QCheckBox();
......@@ -98,6 +110,12 @@ export class Compile {
check_cdas.setText('cdas');
check_cdas.addEventListener('stateChanged', () => {
this.cdas = !this.cdas;
if (check_cdas.isChecked()) {
run_obj.nb_plot_box.text_edit.clear();
run_obj.nb_plot_box.widget.setEnabled(false);
} else {
run_obj.nb_plot_box.widget.setEnabled(true);
}
});
const check_memetic = new QCheckBox();
......@@ -213,6 +231,10 @@ export class Compile {
output_compile.text.insertPlainText(data.toString());
});
run.stderr.on('data', (data) => {
output_compile.text.insertPlainText(data.toString());
});
run.on('exit', (code) => {
if (code === 0) {
output_compile.text.insertPlainText('\n');
......@@ -232,6 +254,8 @@ export class Compile {
});
} else {
output_compile.text.insertPlainText('Compilation failed');
this.ready = 0;
make_clean_btn.setEnabled(true);
file_select.setEnabled(true);
compile_btn.setEnabled(true);
......
......@@ -6,11 +6,11 @@ import sys
from math import ceil
if len(sys.argv) != 3:
print(
"Usage : " + sys.argv[0] + " <nb of generations> <nb of plots>", file=sys.stderr
)
exit(1)
# if len(sys.argv) != 3:
# print(
# "Usage : " + sys.argv[0] + " <nb of generations> <nb of plots>", file=sys.stderr
# )
# exit(1)
# number of generations
nb_gen = int(sys.argv[1])
......
......@@ -7,7 +7,8 @@ import os from 'os'
import { Win_alert } from "./win_alert";
const SCRIPT_PATH = 'src/plot.py';
const SCRIPT_2D_PATH = 'src/plot.py';
const SCRIPT_3D_PATH = 'src/3D_plot.py';
export class Plot_result {
widget: QWidget;
......@@ -32,19 +33,33 @@ export class Plot_result {
this.btn_widget = new QWidget();
}
update_plot(path: string, plot_size: number) {
update_plot(path: string, plot_size: number, type: string, ez_path: string) {
var run: ChildProcess;
var nb_gen = run_obj.option_obj.nb_gen
var plot_path = '';
if (existsSync(SCRIPT_PATH)) {
plot_path = 'src/plot.py';
} else if (existsSync('plot.py')) {
plot_path = 'plot.py';
if (type === '') {
if (existsSync(SCRIPT_2D_PATH)) {
plot_path = 'src/plot.py';
} else if (existsSync('plot.py')) {
plot_path = 'plot.py';
} else {
this.image_label.setFixedSize(200, 30);
this.image_label.setText('Error : plot script not found');
console.log('Error : plot script not found');
}
} else {
this.image_label.setText('Error : plot script not found');
return;
if (existsSync(SCRIPT_3D_PATH)) {
plot_path = 'src/3D_plot.py';
} else if (existsSync('3D_plot.py')) {
plot_path = '3D_plot.py';
} else {
this.image_label.setFixedSize(200, 30);
this.image_label.setText('Error : plot script not found');
console.log('Error : plot script not found');
}
console.log('ok');
}
if (isNaN(nb_gen)) {
......@@ -53,7 +68,7 @@ export class Plot_result {
val === -1 ? nb_gen = 30 : nb_gen = val;
}
run = spawn('python3', [plot_path, nb_gen.toString(), plot_size.toString()], { timeout: 20000 });
run = spawn('python3', [plot_path, nb_gen.toString(), plot_size.toString(), ez_path], { timeout: 20000 });
running_plot.push(run);
......@@ -71,6 +86,7 @@ export class Plot_result {
} else {
this.image_label.setFixedSize(200, 30);
this.image_label.setText('Error : graph not found');
console.log('Error : graph not found');
}
} else {
this.image_label.setFixedSize(200, 30);
......
......@@ -126,7 +126,7 @@ export class Pseudo_term {
}
}
run(cmd: string, plot_size: number, params?: string, dir?: string, rank?: number) {
run(cmd: string, plot_size: number, type: string, params?: string, dir?: string, rank?: number) {
var array_params: string[] = [];
if (params == undefined) {
this.text.insertPlainText('\n$ ' + cmd + '\n');
......@@ -161,6 +161,10 @@ export class Pseudo_term {
return -1;
});
child.stderr.on('data', (data) => {
this.text.insertPlainText(data);
});
child.stdout.on('data', (data) => {
if (child.pid === initial_proc.pid)
this.text.insertPlainText(data.toString());
......@@ -188,7 +192,7 @@ export class Pseudo_term {
run_obj.running_label.setText('Plotting results ...');
run_obj.running_label.show();
plot_obj.update_plot(process.cwd() + '/plotting/fig.svg', plot_size);
plot_obj.update_plot(process.cwd() + '/plotting/fig.svg', plot_size, type, run_obj.dir_path + '/objectives');
console.log("child process terminated with code " + code);
run_obj.finished_label.setText('Completed Runs : ' + (run_obj.batch_size - running_proc.length) + '/' + run_obj.batch_size);
......
import { Pseudo_term } from './pseudo_term';
import { Win_alert } from './win_alert';
import * as util from './utilities';
import { running_proc, run_obj, tab_menu } from './index';
import { compile_obj, running_proc, tab_menu } from './index';
import { QGridLayout, QLabel, QWidget, QBoxLayout, QPushButton, QCheckBox, Direction, QProgressBar } from '@nodegui/nodegui';
import { Run_options } from './run_options_win';
import { Parent_options_win } from './parents_options_win';
import { Offspring_options_win } from './offspring_options_win';
import { Island_options_win } from './island_options_win';
import { plot_obj } from './index';
import * as plot_generation from './plot_generation';
import * as fs_extra from 'fs-extra';
import { Advanced_option_widget } from './advanced_option_widget';
import { running_plot } from './index';
import { ChildProcess } from 'child_process';
import { isBuffer, isUndefined } from 'util';
// first process
......@@ -341,7 +340,15 @@ export class Run_tab {
this.options = this.options.concat(' --reduceParentsPressure ' + this.parent_obj.reduce_pressure.toString());
// run starts here
var run = output_run.run(cmd, this.nb_plots, this.options, this.dir_path, i + 1);
if (compile_obj.nsgaii) {
var run = output_run.run(cmd, this.nb_plots, 'nsgaii', this.options, this.dir_path, i + 1);
} else if (compile_obj.nsgaiii) {
var run = output_run.run(cmd, this.nb_plots, 'nsgaiii', this.options, this.dir_path, i + 1);
} else if (compile_obj.cdas) {
var run = output_run.run(cmd, this.nb_plots, 'cdas', this.options, this.dir_path, i + 1);
} else {
var run = output_run.run(cmd, this.nb_plots, '', this.options, this.dir_path, i + 1);
}
if (i === 0)
initial_proc = run;
......@@ -353,19 +360,15 @@ export class Run_tab {
this.running_label.show();
run.on('close', (code, signal) => {
if (signal?.toString() === 'SIGTERM') {
if (signal?.toString() === 'SIGTERM' || code !== 0) {
this.enable_buttons(true);
} else if (running_proc.length !== 0) {
this.running_label.setText('Runs in progress ...');
this.running_label.show();
}
if (signal?.toString() === 'SIGTERM') {
this.running_label.setText('Interrupted');
this.running_label.show();
running_plot.length = 0;
} else if (running_proc.length !== 0) {
this.running_label.setText('Runs in progress ...');
this.running_label.show();
}
});
}
......@@ -431,7 +434,8 @@ export class Run_tab {
this.island_btn.setEnabled(true);
this.offsp_btn.setEnabled(true);
this.general_option_btn.setEnabled(true);
this.nb_plot_box.widget.setEnabled(true);
if (!compile_obj.nsgaii && !compile_obj.nsgaiii && !compile_obj.cdas)
this.nb_plot_box.widget.setEnabled(true);
tab_menu.tabs[0].setEnabled(true);
} else {
this.activate_island_model.setEnabled(false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment