Commit 0dfc7452 authored by LIGNEUL CLEMENT's avatar LIGNEUL CLEMENT
Browse files

improve parser + adjustments

parent 74484824
......@@ -228,11 +228,11 @@ export class Compile {
});
} else {
console.log("return 1");
make_clean_btn.setEnabled(true);
file_select.setEnabled(true);
compile_btn.setEnabled(true);
option_widget.setEnabled(true);
compiling_label.hide();
}
});
}
......@@ -287,8 +287,6 @@ export class Compile {
run_obj.setEzFileAddress(this.ez_file_address);
}
}
// console.log(this.ez_file_address);
});
// load file box
......
......@@ -9,9 +9,11 @@ import { Plot_result } from './plot_tab';
import fs from 'fs';
import { exit } from 'process';
// list of running child processes
// array of running child processes
export let running_proc: ChildProcess[] = [];
export let running_plot: ChildProcess[] = [];
// main window
const global_win = new QMainWindow();
global_win.setWindowTitle("EASEA Compiler");
......@@ -43,7 +45,7 @@ export const plot_obj = new Plot_result();
plot.setLayout(plot_obj.generate());
const tab_menu = new QTabWidget();
export const tab_menu = new QTabWidget();
tab_menu.addTab(compile, new QIcon(), 'Compile');
tab_menu.addTab(run, new QIcon(), 'Run');
tab_menu.addTab(plot, new QIcon(), 'Result Plot')
......
......@@ -92,7 +92,8 @@ export class Island_options_win{
var errors = [];
var ok = 1;
if(isNaN(Number(proba_migration.text_edit.text()))){
var proba_migr = Number(proba_migration.text_edit.text());
if(isNaN(proba_migr) || proba_migr < 0 || proba_migr > 1){
ok = 0;
errors.push('Migration Probability');
}
......@@ -115,11 +116,11 @@ export class Island_options_win{
reset_btn.addEventListener('clicked', ()=>{
file_loaded.setText('IP file :');
proba_migration.text_edit.setText('');
proba_migration.text_edit.clear();
reevaluate_im.setChecked(false);
server_port.text_edit.setText('');
server_port.text_edit.clear();
});
reset_btn.setFixedSize(100, 25);
......
......@@ -69,7 +69,7 @@ export class Offspring_options_win{
reduce_off_pressure.widget.setEnabled(true);
} else {
reduce_off_pressure.widget.setEnabled(false);
reduce_off_pressure.text_edit.setText('');
reduce_off_pressure.text_edit.clear();
}
text = reduce_off_op.text_edit.text();
......@@ -142,13 +142,13 @@ export class Offspring_options_win{
const reset_btn = new QPushButton();
reset_btn.setText('Reset');
reset_btn.addEventListener('clicked', ()=>{
reduce_off_op.text_edit.setText('');
reduce_off_op.text_edit.clear();
reduce_off_pressure.text_edit.setText('');
reduce_off_pressure.text_edit.clear();
nb_off.text_edit.setText('');
nb_off.text_edit.clear();
surviving_offspring.text_edit.setText('');
surviving_offspring.text_edit.clear();
});
reset_btn.setFixedSize(100, 25);
......
......@@ -53,7 +53,7 @@ export class Parent_options_win{
reduce_parent_pressure.widget.setEnabled(true);
} else {
reduce_parent_pressure.widget.setEnabled(false);
reduce_parent_pressure.text_edit.setText('');
reduce_parent_pressure.text_edit.clear();
}
text = reduce_parent_op.text_edit.text();
......@@ -121,11 +121,11 @@ export class Parent_options_win{
const reset_btn = new QPushButton();
reset_btn.setText('Reset');
reset_btn.addEventListener('clicked', ()=>{
surviving_parent.text_edit.setText('');
surviving_parent.text_edit.clear();
reduce_parent_pressure.text_edit.setText('');
reduce_parent_pressure.text_edit.clear();
reduce_parent_op.text_edit.setText('');
reduce_parent_op.text_edit.clear();
});
reset_btn.setFixedSize(100, 25);
......
from os import name
import os
from pandas.io.parsers import read_csv
import plotly.express as px
import plotly.graph_objects as go
import sys
from math import ceil
# df = read_csv(
# "https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv"
# )
# fig = go.Figure()
# fig.add_trace(
# go.Violin(
# x=df["day"],
# y=df["total_bill"],
# legendgroup="M",
# scalegroup="M",
# name="M",
# line_color="red",
# )
# )
# fig.add_trace(
# go.Violin(
# x=df["day"],
# y=df["total_bill"],
# legendgroup="F",
# scalegroup="F",
# name="F",
# line_color="green",
# )
# )
if(len(sys.argv) != 3):
print("Usage : " + sys.argv[0] + " <nb of generations> <nb of plots>" , file=sys.stderr)
if len(sys.argv) != 3:
print(
"Usage : " + sys.argv[0] + " <nb of generations> <nb of plots>", file=sys.stderr
)
exit(1)
# number of generations
......@@ -46,27 +19,27 @@ nb_plots = int(sys.argv[2])
treshold = ceil(nb_gen / nb_plots)
df = read_csv('plotting/data.csv')
df = read_csv("plotting/data.csv")
fig = go.Figure()
for i in range(nb_plots):
for i in range(1, nb_plots + 1):
fig.add_trace(
go.Violin(
y=df["BEST_FIT"] [df["GEN"] < (i * treshold)][df["GEN"] >= treshold * (i-1)],
y=df["BEST_FIT"][df["GEN"] < (i * treshold)][
df["GEN"] >= treshold * (i - 1)
],
fillcolor="red",
line_color="black",
name= '\u2264' + str((i+1)*treshold)
name="<" + str((i) * treshold),
)
)
fig.update_traces(box_visible=True, meanline_visible=True, points="all")
fig.update_layout(
# violinmode="group",
title={
"text": "Results",
"text": "Fitness through generations",
"y": 0.9,
"x": 0.5,
"xanchor": "center",
......@@ -74,13 +47,10 @@ fig.update_layout(
},
)
fig.update_xaxes(
title_text="Generations"
)
fig.update_xaxes(title_text="Generations")
fig.update_yaxes(
title_text="Best Fitness"
)
fig.update_yaxes(title_text="Best Fitness")
fig.write_image("plotting/fig.svg")
fig.write_html("plotting/fig.html")
fig.write_image("plotting/fig.svg", engine="kaleido", scale=2)
......@@ -3,7 +3,6 @@ import fs from 'fs';
export const data_csv = 'plotting/data.csv';
export function parser(data: string):number[][]{
var nb_lines = 0; // for final array
var str = data.toString()
// parse lines
var lines = str.split('\n'); //(/(\r?\n)/g);
......@@ -18,7 +17,6 @@ export function parser(data: string):number[][]{
var col = lines[i].split('\t');
if(col.length === 8){
// nb_lines++;
for(var j = 0; j < 8; j++){
// time
if(col[j].charAt(col[j].length - 1) === 's')
......@@ -36,32 +34,10 @@ export function parser(data: string):number[][]{
}
}
}
// var final: number[][] = [];
// for(var i = 0; i < nb_lines; i++)
// final.push([]);
// for(var i = 0; i < nb_lines; i++){
// for(var j = 0; j < 8; j++){
// final[i].push(val_col[i][j]);
// }
// }
// for(var i = 0; i < val_col.length; i++){
// for(var j = 0; j < val_col[i].length; j++){
// if(isNaN(Number(val_col[i][j])))
// console.log('nan');
// else
// console.log(Number(val_col[i][j]));
// }
// console.log('\n');
// }
return val_col;
}
// debug
export function print_data(array: number[][]){
for(var i = 0; i < array.length; i++){
if(array[i].length === 8){
......
import { QBoxLayout, QLabel, QPixmap, QPushButton, QTextEdit, QWidget, WidgetEventTypes } from "@nodegui/nodegui";
import { QBoxLayout, QLabel, QPixmap, QPushButton, QTextEdit, QWidget, TransformationMode, WidgetEventTypes } from "@nodegui/nodegui";
import { Pseudo_term } from "./pseudo_term";
import fs from 'fs';
import { exec, execSync, spawnSync, spawn } from "child_process";
import fs, { existsSync } from 'fs';
import { exec, execSync, spawnSync, spawn, ChildProcess } from "child_process";
import * as util from './utilities';
import { running_proc } from ".";
import { running_plot, running_proc } from "./index";
import { run_obj } from './index'
export class Plot_result{
......@@ -23,26 +23,82 @@ export class Plot_result{
this.image_label = new QLabel();
}
update_plot(path: string){
update_plot(path: string, plot_size: number){
this.image_label.setText('');
try{
var nb_gen = run_obj.option_obj.nb_gen
execSync('python3 "src/plot.py" ' + nb_gen + ' 5', {timeout:20000});
} catch(e) {
try{
execSync('python3 "plot.py" 10 5', {timeout:20000});
} catch {
console.log('Error in "plot.py" : ' + e);
this.image_label.setText('Error in the python script, the graph can\'t be displayed');
return;
}
}
this.image_path = path;
if(this.image.load(path)){
this.image_label.setPixmap(this.image);
var run: ChildProcess;
// tester l'existence du fichier
var nb_gen = run_obj.option_obj.nb_gen
var plot_path = '';
if(existsSync('src/plot.py')){
plot_path = 'src/plot.py';
} else if(existsSync('plot.py')){
plot_path = 'plot.py';
} else {
this.image_label.setText('Error : graph not found');
this.image_label.setText('Error : plot script not found');
return;
}
if(isNaN(nb_gen)){
var val = this.get_generations(run_obj.ez_file_address);
console.log('nb gen detected in file : ' + val);
val === -1? nb_gen = 30: nb_gen = val;
}
console.log('nb gen : ' + nb_gen);
run = spawn('python3', [plot_path, nb_gen.toString(), plot_size.toString()] , {timeout:20000});
running_plot.push(run);
run.on('exit', (code)=>{
const index = running_plot.indexOf(run, 0);
if(index > -1){
if(running_plot.length === 1){
running_proc.pop();
} else {
running_plot.splice(index, 1);
}
}
if(code === 0){
this.image_path = path;
if(this.image.load(path)){
this.image_label.setPixmap(this.image.scaled(900,600)); // 1 keep ratio
} else {
this.image_label.setText('Error : graph not found');
}
} else {
this.image_label.setText('This graph can\'t be displayed');
}
if(running_plot.length === 0){
run_obj.running_label.hide();
}
});
}
get_generations(filename: string): number{
var text_file = fs.readFileSync(filename, 'utf-8');
var lines = text_file.split('\n');
for(var i = 0; i < lines.length; i++){
// remove all spaces at the beginning
while(lines[i][0] === ' ' || lines[i][0] === '\t')
lines[i] = lines[i].substring(1, lines[i].length);
var col = lines[i].split(' ');
if (col[0].toLowerCase() === 'number' && col[1].toLowerCase() === 'of'){
if (col[2].toLowerCase() === 'generations:'){
return Number(col[3]);
} else if (col[2].toLowerCase() === 'generations'){
return Number(col[4]);
}
}
}
return -1;
}
generate(){
......@@ -54,11 +110,12 @@ export class Plot_result{
// graph
this.image.load(this.image_path);
this.image_label.setPixmap(this.image);
this.image_label.setText('No graph to display');
const ps_console = new Pseudo_term('Plot :');
const btn = new QPushButton();
btn.setText('Go');
btn.setText('Save Static Image');
btn.addEventListener('clicked', ()=>{
ps_console.run_command('pwd');
ps_console.run_command('ls', ['-la']);
......@@ -68,9 +125,10 @@ export class Plot_result{
spawn('open', ['plotting/fig.html'], {detached:true});
})
this.layout.addStretch();
this.layout.addWidget(this.image_label);
// this.layout.addWidget(btn);
// this.layout.addWidget(ps_console.window);
this.layout.addStretch();
return this.layout;
}
}
\ No newline at end of file
......@@ -43,13 +43,6 @@ export class Processus{
});
}
remove_proc(){
this.proc_layout.removeWidget(this.seed_text);
this.proc_layout.removeWidget(this.seed_text);
this.proc_layout.removeWidget(this.proc_label);
this.proc_widget.close();
}
enable(){
this.seed_text.setReadOnly(false);
this.seed_text.setPlaceholderText('Default if empty');
......
......@@ -2,10 +2,11 @@ const { QGridLayout } = require("@nodegui/nodegui");
import { QPlainTextEdit, QWidget, QLabel, QPushButton } from '@nodegui/nodegui';
import { spawn } from 'child_process';
import { spawnSync } from 'child_process';
import { running_proc } from '.';
import { running_plot, running_proc, tab_menu } from '.';
import { Win_alert } from './win_alert';
import * as plot_generation from './plot_generation';
import { plot_obj, run_obj } from './index';
import { initial_proc } from './run_tab';
require('child_process').spawn('node', ['--version'], {
env: {
......@@ -169,7 +170,7 @@ export class Pseudo_term{
}
}
run(cmd: string, params?: string, dir?: string, rank?: number){
run(cmd: string, plot_size: number, params?: string, dir?: string, rank?: number){
var array_params: string[] = [];
if(params == undefined){
this.text.insertPlainText('\n$ ' + cmd + '\n');
......@@ -205,11 +206,13 @@ export class Pseudo_term{
} else {
new Win_alert(err + '');
}
running_proc.length = 0;
running_plot.length = 0;
return -1;
});
child.stdout.on('data', (data) => {
if(child.pid === running_proc[0].pid)
if(child.pid === initial_proc.pid)
this.text.insertPlainText(data.toString());
run_obj.running_label.setText('Writing results ...');
......@@ -225,11 +228,22 @@ export class Pseudo_term{
// this.text.insertPlainText(data.toString());
// });
child.on('close', (code)=>{
running_proc.pop();
child.on('exit', (code)=>{
const index = running_proc.indexOf(child, 0);
if(index > -1){
if(running_proc.length === 1){
running_proc.pop();
} else {
running_proc.splice(index, 1);
}
}
if(code !== 0)
return;
run_obj.running_label.setText('Plotting results ...');
run_obj.running_label.show();
plot_obj.update_plot(process.cwd() + '/plotting/fig.svg');
plot_obj.update_plot(process.cwd() + '/plotting/fig.svg', plot_size);
// console.log(process.cwd() + '/' + plot_generation.data_csv);
console.log("child process terminated with code " + code);
})
......
......@@ -192,11 +192,12 @@ export class Run_options {
const nb_gen = new Advanced_option_widget('Nb Generations :', 2);
nb_gen.text_edit.addEventListener('textChanged', ()=>{
var text = nb_gen.text_edit.text();
var val = Number(text);
if(text === ''){
this.nb_gen = NaN;
return;
}
var val = Number(text);
if(!isNaN(val)){
this.nb_gen = val;
}
......@@ -222,7 +223,7 @@ export class Run_options {
select_pressure.widget.setEnabled(true);
} else {
select_pressure.widget.setEnabled(false);
select_pressure.text_edit.setText('');
select_pressure.text_edit.clear();
}
this.select_op = select_op.text_edit.text();
});
......@@ -248,7 +249,7 @@ export class Run_options {
reduce_final_pressure.widget.setEnabled(true);
} else {
reduce_final_pressure.widget.setEnabled(false);
reduce_final_pressure.text_edit.setText('');
reduce_final_pressure.text_edit.clear();
}
this.reduce_final_op = reduce_final_op.text_edit.text();
});
......@@ -619,7 +620,7 @@ export class Run_options {
this.thread_number = 1;
seed_text.setText('');
seed_text.clear();
this.seed = NaN;
for(var i = 0; i < this.proc_tab.length; i++){
......@@ -628,31 +629,31 @@ export class Run_options {
check_plot.setChecked(false);
compression_arg.text_edit.setText('');
compression_arg.text_edit.clear();
popu_size.text_edit.setText('');
popu_size.text_edit.clear();
combo_elite_type.setCurrentText('Default');
nb_elite.text_edit.setText('');
nb_elite.text_edit.clear();
nb_gen.text_edit.setText('');
nb_gen.text_edit.clear();
time_limit.text_edit.setText('');
time_limit.text_edit.clear();
select_op.text_edit.setText('');
select_op.text_edit.clear();
select_pressure.text_edit.setText('');
select_pressure.text_edit.clear();
reduce_final_op.text_edit.setText('');
reduce_final_op.text_edit.clear();
reduce_final_pressure.text_edit.setText('');
reduce_final_pressure.text_edit.clear();
opti_it.text_edit.setText('');
opti_it.text_edit.clear();
baldwinism.text_edit.setText('');
baldwinism.text_edit.clear();
output_filename.text_edit.setText('');
output_filename.text_edit.clear();
file_loaded.setText('Initial Population :');
......@@ -672,19 +673,15 @@ export class Run_options {
start_from_file.setChecked(false);
fstgpu.text_edit.setText('');
lstgpu.text_edit.setText('');
u1.text_edit.setText('');
u2.text_edit.setText('');
u3.text_edit.setText('');
fstgpu.text_edit.clear();
u4.text_edit.setText('');
lstgpu.text_edit.clear();
u5.text_edit.setText('');
u1.text_edit.clear();
u2.text_edit.clear();
u3.text_edit.clear();
u4.text_edit.clear();
u5.text_edit.clear();
});
// regroup buttons
......
import { Pseudo_term } from './pseudo_term';
import {Win_alert } from './win_alert';
import * as util from './utilities';
import { running_proc, run_obj } from './index';
import { running_proc, run_obj, tab_menu } from './index';
import { QGridLayout, QLabel, QWidget, QBoxLayout, QPushButton, QCheckBox } from '@nodegui/nodegui';
import { Run_options } from './run_options_win';
import { Parent_options_win } from './parents_options_win';
......@@ -11,6 +11,11 @@ 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';