diff --git a/act/analysis.py b/act/analysis.py index ca3733c..8e7b2d9 100644 --- a/act/analysis.py +++ b/act/analysis.py @@ -144,14 +144,9 @@ def save_mse_corr( def print_run_stats(config: SimulationConfig): - output_folder = utils.get_output_folder_name(config) + model_data_dir = utils.get_last_model_data_folder_name(config) + target_params = config["optimization_parameters"].get("target_params") - if(config["run_mode"] == "segregated"): - segregation_index = utils.get_segregation_index(config) - segregation_dir = f"seg_module_{segregation_index+1}/" - model_data_dir = os.path.join(output_folder, segregation_dir) - else: - model_data_dir = output_folder + "model_data/" pred_passive_json_path = model_data_dir + "pred_passive_properties.json" metrics = pd.read_csv(model_data_dir + "metrics.csv") preds_df = pd.read_csv(model_data_dir + "pred.csv", index_col=0) @@ -169,7 +164,7 @@ def print_run_stats(config: SimulationConfig): ] preds = np.array(preds_df) - print(output_folder) + print(model_data_dir) print(f"Med MSE: {metrics['mse'].median():.4f} ({metrics['mse'].std():.4f})") print(f"Med Corr: {metrics['corr'].median():.4f} ({metrics['corr'].std():.4f})") print() diff --git a/act/simulator.py b/act/simulator.py index 5b9ffd4..cabf826 100644 --- a/act/simulator.py +++ b/act/simulator.py @@ -72,12 +72,12 @@ def _run_generate_target_traces(config: SimulationConfig, ignore_segregation=Fal def _run(config: SimulationConfig): + if config["optimization_parameters"]["num_epochs"] < 1: raise ValueError("Number of epochs is expected to be >= 1.") - - output_folder = utils.get_output_folder_name(config) + "_temp_/" - if not os.path.exists(output_folder): - os.mkdir(output_folder) + + output_folder = utils.create_model_data_folder(config) + segregation_index = utils.get_segregation_index(config) # if there is a target_cell specified then use it too os.mkdir(temp_modfiles_dir) @@ -88,7 +88,6 @@ def _run(config: SimulationConfig): os.system(f"nrnivmodl {temp_modfiles_dir}") ltohto = False logger = ACTLogger() - segregation_index = utils.get_segregation_index(config) # if needed if config["run_mode"] == "segregated" and config["segregation"][ segregation_index ].get("use_lto_amps", False): @@ -374,20 +373,20 @@ def _run(config: SimulationConfig): learned_params = {param: predict for param, predict in zip(params, predictions)} if config["run_mode"] == "segregated": # save a copy of the outputs for future development - base_output_folder = utils.get_output_folder_name(config) - run_output_folder_name = f"{config['run_mode']}" - seg_folder = os.path.join( - base_output_folder, f"seg_module_{segregation_index+1}" - ) - shutil.move(output_folder, seg_folder) + #base_output_folder = utils.get_output_folder_name(config) + #run_output_folder_name = f"{config['run_mode']}" + #seg_folder = os.path.join( + #base_output_folder, f"{random_seed}-seed_module_{segregation_index+1}" + #) + #shutil.move(output_folder, seg_folder) utils.update_segregation(config, learned_params) else: - base_output_folder = utils.get_output_folder_name(config) - orig_folder = os.path.join( - base_output_folder, "model_data" - ) - shutil.move(output_folder, orig_folder) - utils.save_learned_params(learned_params) + #base_output_folder = utils.get_output_folder_name(config) + #orig_folder = os.path.join( + #base_output_folder, f"{random_seed}-seed_model_data" + #) + #shutil.move(output_folder, orig_folder) + utils.save_learned_params(learned_params, config) def run_generate_target_traces( diff --git a/act/utils.py b/act/utils.py index fe6629d..e04e23d 100644 --- a/act/utils.py +++ b/act/utils.py @@ -23,7 +23,6 @@ pc = h.ParallelContext() # object to access MPI methods MPI_RANK = int(pc.id()) - def create_output_folder(config: SimulationConfig, overwrite=True) -> str: if(config["output"]["auto_structure"] == True): print("AUTO STRUCTURED") @@ -45,14 +44,81 @@ def create_output_folder(config: SimulationConfig, overwrite=True) -> str: def get_output_folder_name(config: SimulationConfig) -> str: cell_name = config["cell"]["name"] num_slices = f"{config['optimization_parameters']['parametric_distribution']['n_slices']}" - random_seed = f"{config['optimization_parameters']['random_seed']}" run_mode = f"{config['run_mode']}" #"segregated" "origin if(run_mode == "segregated"): run_mode_name = "seg" else: run_mode_name = "orig" - return f"./output/{cell_name}_{run_mode_name}_{num_slices}-slice_{random_seed}-seed/" + return f"./output/{cell_name}_{run_mode_name}_{num_slices}-slice/" + +def get_sim_data_folder_name(config: SimulationConfig) -> str: + segregation_index = get_segregation_index(config) + if config["run_mode"] == "segregated": + sim_dir = get_output_folder_name(config) + "sim_data/" + f"module_{segregation_index+1}/" + else: + sim_dir = get_output_folder_name(config) + "sim_data/" + return sim_dir + +def get_param_values_file(config: SimulationConfig) -> str: + random_seed = f"{config['optimization_parameters']['random_seed']}" + return get_output_folder_name(config) + "sim_data/" + f"parameter_values_{random_seed}-seed.json" + +def get_sim_output_folder_name(config: SimulationConfig) -> str: + return get_sim_data_folder_name(config) + "output/" + +def create_model_data_folder(config: SimulationConfig) -> str: + segregation_index = get_segregation_index(config) + random_seed = f"{config['optimization_parameters']['random_seed']}" + if config["run_mode"] == "segregated": + + output_folder = get_output_folder_name(config) + "model_data/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + output_folder = output_folder + f"{random_seed}-seed/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + output_folder = output_folder + f"module_{segregation_index+1}/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + else: + output_folder = get_output_folder_name(config) + "model_data/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + output_folder = output_folder + f"{random_seed}-seed/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + return output_folder + +def get_model_data_folder_name(config: SimulationConfig) -> str: + output_dir = get_output_folder_name(config) + random_seed = f"{config['optimization_parameters']['random_seed']}" + segregation_index = get_segregation_index(config) + if(config["run_mode"] == "segregated"): + model_data_dir = output_dir + "model_data/"+ f"{random_seed}-seed/" + f"module_{segregation_index+1}/" + else: + model_data_dir = output_dir + "model_data/"+ f"{random_seed}-seed/" + return model_data_dir + +def get_last_model_data_folder_name(config: SimulationConfig) -> str: + # This is used for the plotting scripts because the module # was incremented, so we need the "last run" + output_dir = get_output_folder_name(config) + random_seed = f"{config['optimization_parameters']['random_seed']}" + segregation_index = get_segregation_index(config) + if(config["run_mode"] == "segregated"): + model_data_dir = output_dir + "model_data/"+ f"{random_seed}-seed/" + f"module_{segregation_index}/" + else: + model_data_dir = output_dir + "model_data/"+ f"{random_seed}-seed/" + return model_data_dir def set_cell_parameters(cell, parameter_list: list, parameter_values: list) -> None: for sec in cell.all: @@ -198,8 +264,7 @@ def cleanup_simulation(): def get_segregation_index(config: SimulationConfig): - output_dir = get_output_folder_name(config) - parameter_values_file = output_dir + "sim_data" + "parameter_values.json" + parameter_values_file = get_param_values_file(config) if config["run_mode"] != "segregated": return -1 @@ -215,7 +280,7 @@ def get_segregation_index(config: SimulationConfig): def load_preset_params(config: SimulationConfig): # Returns a dict of learned params from segregation # if segregation is not used then returns an empty dict - parameter_values_file = "parameter_values.json" + parameter_values_file = get_param_values_file(config) if config["run_mode"] != "segregated": return {} @@ -239,7 +304,7 @@ def load_preset_params(config: SimulationConfig): def load_learned_params(config: SimulationConfig): # Returns a dict of learned params from segregation # if segregation is not used then returns an empty dict - parameter_values_file = "parameter_values.json" + parameter_values_file = get_param_values_file(config) if not os.path.exists(parameter_values_file): return {} @@ -250,7 +315,7 @@ def load_learned_params(config: SimulationConfig): def get_learned_variability(config: SimulationConfig): - parameter_values_file = "parameter_values.json" + parameter_values_file = get_param_values_file(config) lv = 0 if os.path.exists(parameter_values_file): with open(parameter_values_file, "r") as fp: @@ -261,7 +326,7 @@ def get_learned_variability(config: SimulationConfig): def get_learned_variability_params(config: SimulationConfig): - parameter_values_file = "parameter_values.json" + parameter_values_file = get_param_values_file(config) lvp = [] if os.path.exists(parameter_values_file): with open(parameter_values_file, "r") as fp: @@ -278,8 +343,8 @@ def update_segregation(config: SimulationConfig, learned_params): # And updates the parameter_values.json if that parameter was # in the current segregation index # learned_params = {'channel'(str):value(float),} - output_dir = get_output_folder_name(config) + "sim_data/" - parameter_values_file = output_dir + "parameter_values.json" + output_dir = get_sim_data_folder_name(config) + parameter_values_file = get_param_values_file(config) if os.path.exists(parameter_values_file): print(f"Updating {parameter_values_file} for learned parameters") with open(parameter_values_file, "r") as fp: @@ -346,8 +411,8 @@ def update_segregation(config: SimulationConfig, learned_params): ) -def save_learned_params(learned_params): - parameter_values_file = "parameter_values.json" +def save_learned_params(learned_params, config: SimulationConfig): + parameter_values_file = get_param_values_file(config) if os.path.exists(parameter_values_file): print(f"Updating {parameter_values_file} for learned parameters") with open(parameter_values_file, "r") as fp: @@ -360,9 +425,9 @@ def save_learned_params(learned_params): def build_parametric_network(config: SimulationConfig): - output_dir = get_output_folder_name(config) + "sim_data/" + output_dir = get_sim_data_folder_name(config) config_file = output_dir + "simulation_act_simulation_config.json" - parameter_values_file = output_dir + "parameter_values.json" + parameter_values_file = get_param_values_file(config) params = [p["channel"] for p in config["optimization_parameters"]["params"]] @@ -615,10 +680,10 @@ def generate_parametric_traces(config: SimulationConfig): traces for a large collection of cells and generates an h5 file for injestion later. """ - output_dir = get_output_folder_name(config) + "sim_data/" + output_dir = get_sim_data_folder_name(config) passive_properties = config.get("cell", {}).get("passive_properties", None) config_file = output_dir + "simulation_act_simulation_config.json" - parameter_values_file = output_dir + "parameter_values.json" + parameter_values_file = get_param_values_file(config) with open(parameter_values_file) as f: param_dict = json.load(f) params = param_dict["parameters"] @@ -673,8 +738,8 @@ def load_parametric_traces(config: SimulationConfig, drop_ramp=False): """ Return a torch tensor of all traces in the specified h5 file """ - output_dir = get_output_folder_name(config) + "sim_data/" - parameter_values_file = output_dir + "parameter_values.json" + output_dir = get_sim_data_folder_name(config) + parameter_values_file = get_param_values_file(config) traces_file = output_dir + "output/v_report.h5" if not os.path.exists(parameter_values_file) or not os.path.exists(traces_file): diff --git a/simulation/analyze_res.py b/simulation/analyze_res.py index d5d0886..b1f27e5 100644 --- a/simulation/analyze_res.py +++ b/simulation/analyze_res.py @@ -7,11 +7,13 @@ from simulation_configs import selected_config from act import analysis +import meta_sweep - -def main(): +def main(config): analysis.print_run_stats(selected_config) if __name__ == "__main__": - main() + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() + main(selected_config) diff --git a/simulation/batch_generate_traces_sweep.sh b/simulation/batch_generate_traces_sweep.sh new file mode 100644 index 0000000..677237f --- /dev/null +++ b/simulation/batch_generate_traces_sweep.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#SBATCH -N 1 +#SBATCH -n 48 +#SBATCH -W +#SBATCH --qos=normal +#SBATCH --job-name=act +#SBATCH --output=output/bmtk_sim.out +#SBATCH --time 0-12:00 + +START=$(date) +mpiexec nrniv -mpi -python generate_traces.py --sweep +#mpiexec ./components_homogenous/mechanisms/x86_64/special -mpi run_network.py simulation_configECP_base_homogenous.json +END=$(date) + +printf "Start: $START \nEnd: $END\n" + +echo "Done running model at $(date)" \ No newline at end of file diff --git a/simulation/generate_arma_stats.py b/simulation/generate_arma_stats.py index fbd3ada..75a29c6 100644 --- a/simulation/generate_arma_stats.py +++ b/simulation/generate_arma_stats.py @@ -4,20 +4,42 @@ from act import utils from simulation_configs import selected_config import warnings +import os.path +import meta_sweep + warnings.filterwarnings("ignore") if __name__ == "__main__": - traces, params, amps = utils.load_parametric_traces(selected_config) - segregation_index = utils.get_segregation_index(selected_config) - - arima_order = (10, 0, 10) - if selected_config.get("summary_features", {}).get("arima_order"): - arima_order = tuple(selected_config["summary_features"]["arima_order"]) - if selected_config["run_mode"] == "segregated" and selected_config["segregation"][segregation_index].get("arima_order",None): - print(f"custom arima order for segregation set") - arima_order = tuple(selected_config["segregation"][segregation_index]["arima_order"]) - print(f"ARIMA order set to {arima_order}") - - output_dir = utils.get_output_folder_name(selected_config) + "sim_data/output/arima_stats.json" - utils.arima_coefs_proc_map(traces, output_file=output_dir, arima_order=arima_order) + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() + + output_dir = utils.get_sim_output_folder_name(selected_config) + arma_stats_file = output_dir + "arima_stats.json" + arma_stats_exists = os.path.exists(arma_stats_file) + generate_arma = selected_config["optimization_parameters"]["generate_arma"] + + if (arma_stats_exists): + print("--------------------------------------------------------------------") + print(f"ARMA STATS ALREADY GENERATED - Using stats from: {arma_stats_file}") + print("--------------------------------------------------------------------") + elif (not generate_arma): + print("-------------------------------------------------") + print("ARMA STATS TURNED OFF IN SIMULATION CONFIGURATION") + print("-------------------------------------------------") + else: + traces, params, amps = utils.load_parametric_traces(selected_config) + segregation_index = utils.get_segregation_index(selected_config) + + arima_order = (10, 0, 10) + if selected_config.get("summary_features", {}).get("arima_order"): + arima_order = tuple(selected_config["summary_features"]["arima_order"]) + if selected_config["run_mode"] == "segregated" and selected_config["segregation"][segregation_index].get("arima_order",None): + print(f"custom arima order for segregation set") + arima_order = tuple(selected_config["segregation"][segregation_index]["arima_order"]) + print(f"ARIMA order set to {arima_order}") + + print(output_dir) + + utils.arima_coefs_proc_map(traces, output_file=arma_stats_file, arima_order=arima_order) + diff --git a/simulation/generate_target_traces.py b/simulation/generate_target_traces.py index ed34e93..5a8183d 100644 --- a/simulation/generate_target_traces.py +++ b/simulation/generate_target_traces.py @@ -1,16 +1,31 @@ import sys sys.path.append("../") +import os from act import simulator +from act import utils +import meta_sweep from simulation_configs import selected_config + + if __name__ == "__main__": ignore_segregation = False if '--ignore_segregation' in sys.argv: ignore_segregation = True print('ignoring segregation, typically used for generating final traces') + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() - print("generating traces...") - simulator.run_generate_target_traces(selected_config, subprocess=False, ignore_segregation=ignore_segregation) - print("done") + # Check if target traces are already saved + target_dir = utils.get_output_folder_name(selected_config) + "target/" + target_file_name = selected_config["optimization_parameters"]["target_V_file"] + if(os.path.exists(target_dir + target_file_name)): + print("-----------------------------------------------") + print(f"TARGET DATA ALREADY GENERATED AT: {target_dir}") + print("-----------------------------------------------") + else: + print("generating traces...") + simulator.run_generate_target_traces(selected_config, subprocess=False, ignore_segregation=ignore_segregation) + print("done") diff --git a/simulation/generate_traces.py b/simulation/generate_traces.py index ff3c67c..e06542b 100644 --- a/simulation/generate_traces.py +++ b/simulation/generate_traces.py @@ -1,14 +1,27 @@ from simulation_configs import selected_config +import os + import sys sys.path.append("../") +import meta_sweep -from act.utils import build_parametric_network, generate_parametric_traces +from act.utils import build_parametric_network, generate_parametric_traces, get_sim_output_folder_name if __name__ == "__main__": + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() if "build" in sys.argv: print("Building Network") build_parametric_network(selected_config) else: - print("Generating Traces") - generate_parametric_traces(selected_config) + # Check if data already exists: spikes.h5 and v_report.h5 + sim_data_dir = get_sim_output_folder_name(selected_config) + + if (os.path.exists(sim_data_dir + "spikes.h5")) and (os.path.exists(sim_data_dir + "v_report.h5")): + print("------------------------------------------------------------") + print(f"DATA ALREADY GENERATED FOR THIS MODULE AT: {sim_data_dir}") + print("------------------------------------------------------------") + else: + print("Generating Traces") + generate_parametric_traces(selected_config) diff --git a/simulation/meta_sweep.py b/simulation/meta_sweep.py index 59c62b1..54c6bdc 100644 --- a/simulation/meta_sweep.py +++ b/simulation/meta_sweep.py @@ -1,56 +1,46 @@ import json -import subprocess +import numpy as np -def set_meta_params(): - x = 1 +from simulation_configs import selected_config +def get_meta_params_for_sweep(): + meta_data = json.load(open('meta_params.json')) + run_num = meta_data["run_num"] + + list_param_lens = [] + parameter_slice_length = len(meta_data["parameter_slice_list"]) + list_param_lens.append(parameter_slice_length) + + random_seed_length = len(meta_data["random_seed_list"]) + list_param_lens.append(random_seed_length) + + index_list = get_index_tuple(run_num,list_param_lens) + + config = selected_config + + config["optimization_parameters"]["parametric_distribution"]["n_slices"] = meta_data["parameter_slice_list"][index_list[0]] + config["optimization_parameters"]["random_seed"] = meta_data["random_seed_list"][index_list[1]] + + return config -def run_meta_sweep(): + +def get_index_tuple(run_num, list_param_lens): + return np.unravel_index(run_num, list_param_lens) + +def increment_config_sweep_number(): + # Increment which configuration we are on + meta_data = json.load(open('meta_params.json')) + with open('meta_params.json', 'w') as json_file: + meta_data["run_num"] = meta_data["run_num"] + 1 + json.dump(meta_data, json_file) + +def get_number_of_configs(): meta_data = json.load(open('meta_params.json')) - print(meta_data) - run_mode_list = meta_data["run_mode_list"] - print(run_mode_list) - print(type(run_mode_list)) - cell_list = meta_data["cell_list"] - model_type_list = meta_data["model_type_list"] - parameter_slice_list = meta_data["parameter_slice_list"] - random_seed_list = meta_data["random_seed_list"] - generate_arma_stats = meta_data["generate_arma_stats"] - - if "orig" in run_mode_list: - for cell in cell_list : - for model_type in model_type_list : - for slices in parameter_slice_list : - for seed in random_seed_list : - # Set the parameters - print("SETTING PARAMETERS") - - # Run the Pipeline - print(f"PARAMS: orig_{cell}_{model_type}_{slices}_{seed}") - #subprocess.run("python generate_target_traces.py") - print(f"Target") - #subprocess.run(["python generate_traces.py", "build"]) - print(f"Build") - #subprocess.run("sbatch batch_generate_traces.sh") - print(f"Simulate") - if (generate_arma_stats == True) and (seed == random_seed_list[0]): - print(f"Generating ARMA stats") - #subprocess.run("python generate_arma_stats.py") - - #subprocess.run("python run_simulation.py") - print(f"Run Model") - #subprocess.run("python analyze_res.py") - print(f"Results") - #subprocess.run("python plot_fi.py") - print(f"FI Plot") - #subprocess.run("python plot_learned_parameters.py") - print(f"Final") - - - - if "seg" in run_mode_list: - pass - -# python generate_target_traces.py && python generate_traces.py build && sbatch batch_generate_traces.sh -W && python generate_arma_stats.py && python run_simulation.py && python analyze_res.py && python plot_fi.py && python plot_learned_parameters.py -if __name__ == "__main__": - run_meta_sweep() + list_param_lens = [] + parameter_slice_length = len(meta_data["parameter_slice_list"]) + list_param_lens.append(parameter_slice_length) + + random_seed_length = len(meta_data["random_seed_list"]) + list_param_lens.append(random_seed_length) + + return np.prod(list_param_lens) \ No newline at end of file diff --git a/simulation/plot_arima.py b/simulation/plot_arima.py index ad44fa1..dd74068 100644 --- a/simulation/plot_arima.py +++ b/simulation/plot_arima.py @@ -10,6 +10,7 @@ import numpy as np from statsmodels.graphics.tsaplots import plot_predict import time +import meta_sweep warnings.filterwarnings("ignore") @@ -49,6 +50,8 @@ def plot_arima(cell_id, pq=10): if __name__ == "__main__": + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() traces, params, amps = utils.load_parametric_traces(selected_config) traces = traces.cpu().detach().tolist() diff --git a/simulation/plot_fi.py b/simulation/plot_fi.py index 0fdadf8..4433a6f 100644 --- a/simulation/plot_fi.py +++ b/simulation/plot_fi.py @@ -5,23 +5,17 @@ import sys sys.path.append("../") from act import analysis, utils +import meta_sweep -def main(extra_trace, extra_trace_label, title=None): - config = selected_config +def main(config, extra_trace, extra_trace_label, title=None): inj_dur = config["simulation_parameters"]["h_i_dur"] - + random_seed = f"{config['optimization_parameters']['random_seed']}" output_folder = utils.get_output_folder_name(config) target_params = config["optimization_parameters"].get("target_params") - if(config["run_mode"] == "segregated"): - segregation_index = utils.get_segregation_index(config) - segregation_dir = f"seg_module_{segregation_index+1}/" - model_data_dir = os.path.join(output_folder, segregation_dir) - fi_file = model_data_dir + f"{output_folder[9:-1]}_FI.png" - else: - model_data_dir = output_folder + "model_data/" - fi_file = model_data_dir + f"{output_folder[9:-1]}_FI.png" + model_data_dir = utils.get_last_model_data_folder_name(config) + fi_file = model_data_dir + f"FI.png" traces_file = model_data_dir + "traces.h5" simulated_traces, target_traces, amps = utils.load_final_traces(traces_file) @@ -72,4 +66,6 @@ def main(extra_trace, extra_trace_label, title=None): if args.title: title = args.title - main(extra_trace, extra_label, title=title) + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() + main(selected_config, extra_trace, extra_label, title=title) diff --git a/simulation/plot_learned_parameters.py b/simulation/plot_learned_parameters.py index f5d162b..bb119d2 100644 --- a/simulation/plot_learned_parameters.py +++ b/simulation/plot_learned_parameters.py @@ -9,30 +9,27 @@ sys.path.append("../") from act.analysis import save_plot, plot_fi_curves from act.target_utils import load_target_traces -from act.utils import load_learned_params, get_fi_curve, get_fi_curve_error, get_output_folder_name +from act import utils from act.optim import ACTOptimizer from act.target_utils import DEFAULT_TARGET_V_LTO_FILE, DEFAULT_TARGET_V_HTO_FILE from simulation_configs import selected_config +import meta_sweep # will have to generate target traces (python generate_target_traces.py --ignore_segregation) temp_modfiles_dir = "temp_modfiles" -def save_fi(config, simulated_traces, target_traces, amps): +def save_fi(config, simulated_traces, target_traces, amps, output_file): inj_dur = config["simulation_parameters"]["h_i_dur"] - - output_file = os.path.join( - get_output_folder_name(selected_config), "final" , "final_fi_curve" - ) - - simulated_curve = get_fi_curve(simulated_traces, amps, inj_dur=inj_dur) - target_curve = get_fi_curve(target_traces, amps, inj_dur=inj_dur) + + simulated_curve = utils.get_fi_curve(simulated_traces, amps, inj_dur=inj_dur) + target_curve = utils.get_fi_curve(target_traces, amps, inj_dur=inj_dur) simulated_label = config["output"]["simulated_label"] target_label = config["output"]["target_label"] - err1 = get_fi_curve_error(simulated_traces, target_traces, amps, inj_dur=inj_dur) + err1 = utils.get_fi_curve_error(simulated_traces, target_traces, amps, inj_dur=inj_dur) simulated_label = simulated_label + f" (err: {err1})" curves_list = [ @@ -78,17 +75,40 @@ def run(simulation_config): ) # create output folders - output_folder = os.path.join( - get_output_folder_name(selected_config), "final" - ) - if not os.path.exists(output_folder): - os.makedirs(output_folder, exist_ok=True) + segregation_index = utils.get_segregation_index(simulation_config) + random_seed = f"{simulation_config['optimization_parameters']['random_seed']}" + if simulation_config["run_mode"] == "segregated": + + output_folder = utils.get_output_folder_name(simulation_config) + "final/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + output_folder = output_folder + f"{random_seed}-seed/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + output_folder = output_folder + f"module_{segregation_index}/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + else: + output_folder = utils.get_output_folder_name(simulation_config) + "final/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) + + output_folder = output_folder + f"{random_seed}-seed/" + + if not os.path.exists(output_folder): + os.mkdir(output_folder) dt = simulation_config["simulation_parameters"]["h_dt"] amps = simulation_config["optimization_parameters"]["amps"] simulated_label = simulation_config["output"]["simulated_label"] target_label = simulation_config["output"]["target_label"] - learned_params = load_learned_params(simulation_config) + learned_params = utils.load_learned_params(simulation_config) parameters = [k for k,v in learned_params.items()] target_params = [v for k,v in learned_params.items()] @@ -112,7 +132,8 @@ def run(simulation_config): ) print("saving fi") sv_tensor = torch.cat(sv_list) - save_fi(simulation_config, sv_tensor, target_V, torch.tensor(amps)) + output_file = output_folder + "final_fi_curve.png" + save_fi(simulation_config, sv_tensor, target_V, torch.tensor(amps), output_file) if os.path.exists(DEFAULT_TARGET_V_LTO_FILE): # we have generated an LTO file before and should simulate at end # need to go case by case @@ -273,6 +294,8 @@ def run(simulation_config): if __name__ == '__main__': # will have to generate target traces (python generate_target_traces.py --ignore_segregation) + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() try: run(selected_config) except: diff --git a/simulation/plot_loss.py b/simulation/plot_loss.py index 8b4d6be..6ecd2ef 100644 --- a/simulation/plot_loss.py +++ b/simulation/plot_loss.py @@ -5,7 +5,10 @@ from act import utils from simulation_configs import selected_config import os +import meta_sweep +if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() output_dir = utils.get_output_folder_name(selected_config) if(selected_config["run_mode"] == "segregated"): diff --git a/simulation/plot_target_v.py b/simulation/plot_target_v.py index 41cbd6e..3f87b59 100644 --- a/simulation/plot_target_v.py +++ b/simulation/plot_target_v.py @@ -4,9 +4,11 @@ sys.path.append("../") from act import utils from simulation_configs import selected_config +import meta_sweep - +if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() output_dir = utils.get_output_folder_name(selected_config) target_v_file = output_dir + "target/target_v.json" diff --git a/simulation/plot_traces.py b/simulation/plot_traces.py index 4f10291..78628eb 100644 --- a/simulation/plot_traces.py +++ b/simulation/plot_traces.py @@ -9,6 +9,7 @@ import numpy as np from simulation_configs import selected_config +import meta_sweep config = selected_config @@ -82,6 +83,8 @@ def stats(traces, params_dict): if __name__ == "__main__": + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() output_dir = utils.get_output_folder_name(selected_config) traces_path = output_dir + "sim_data/output/v_report.h5" params_path = output_dir + "sim_data/parameter_values.json" diff --git a/simulation/run_full_pipeline.py b/simulation/run_full_pipeline.py new file mode 100644 index 0000000..c30d88e --- /dev/null +++ b/simulation/run_full_pipeline.py @@ -0,0 +1,59 @@ +import subprocess +from simulation_configs import selected_config +import sys + +import meta_sweep + +# See how many runs are needed for this configuration. +# Original: 1 run - Segregated: n runs depending on # of modules + +def run_single_config(): + run_mode = selected_config["run_mode"] + if run_mode == "original": + number_of_runs = 1 + elif run_mode == "segregated": + number_of_runs = len(selected_config["segregation"]) + + for i in range(0,number_of_runs): + # The whole pipeline is run through these commands + subprocess.run(["python", "generate_target_traces.py"]) + subprocess.run(["python", "generate_traces.py", "build"]) + subprocess.run(["sbatch", "--wait", "batch_generate_traces.sh"]) + subprocess.run(["python", "generate_arma_stats.py"]) + subprocess.run(["python", "run_simulation.py"]) + subprocess.run(["python", "analyze_res.py"]) + subprocess.run(["python", "plot_fi.py"]) + subprocess.run(["python", "plot_learned_parameters.py"]) + +def run_sweep_of_config(): + run_mode = selected_config["run_mode"] + if run_mode == "original": + number_of_runs = 1 + elif run_mode == "segregated": + number_of_runs = len(selected_config["segregation"]) + + number_of_configs = meta_sweep.get_number_of_configs() + + print("------------------------------------------------------") + print(f"REQUESTING {number_of_configs} CONFIGURATIONS TO BE RUN") + print("------------------------------------------------------") + + for i in range(0,number_of_configs): + for j in range(0,number_of_runs): + # The whole pipeline is run through these commands + subprocess.run(["python", "generate_target_traces.py", "--sweep"]) + subprocess.run(["python", "generate_traces.py", "build", "--sweep"]) + subprocess.run(["sbatch", "--wait", "batch_generate_traces_sweep.sh"]) + subprocess.run(["python", "generate_arma_stats.py", "--sweep"]) + subprocess.run(["python", "run_simulation.py", "--sweep"]) + subprocess.run(["python", "analyze_res.py", "--sweep"]) + subprocess.run(["python", "plot_fi.py", "--sweep"]) + subprocess.run(["python", "plot_learned_parameters.py", "--sweep"]) + + meta_sweep.increment_config_sweep_number() + +if __name__ == "__main__": + if '--sweep' in sys.argv: + run_sweep_of_config() + else: + run_single_config() \ No newline at end of file diff --git a/simulation/run_orig_pipeline.sh b/simulation/run_orig_pipeline.sh deleted file mode 100644 index 1ced368..0000000 --- a/simulation/run_orig_pipeline.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -#SBATCH -N 1 -#SBATCH -n 1 -#SBATCH --qos=normal -#SBATCH --job-name=act-orig-pipeline -#SBATCH --output=output/run_orig_pipeline.out -#SBATCH --time 0-12:00 - - - -START=$(date) -python generate_target_traces.py -python generate_traces.py build -sbatch --wait batch_generate_traces.sh -python generate_arma_stats.py -python run_simulation.py -python analyze_res.py -python plot_fi.py -python plot_learned_parameters.py -END=$(date) - -printf "Start: $START \nEnd: $END\n" - -echo "Done running model at $(date)" \ No newline at end of file diff --git a/simulation/run_pipeline.sh b/simulation/run_pipeline.sh new file mode 100644 index 0000000..91c8049 --- /dev/null +++ b/simulation/run_pipeline.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#SBATCH -N 1 +#SBATCH -n 1 +#SBATCH --qos=normal +#SBATCH --job-name=act-orig-pipeline +#SBATCH --output=output/run_pipeline.out +#SBATCH --time 0-12:00 + + + +START=$(date) +python run_full_pipeline.py +END=$(date) + +printf "Start: $START \nEnd: $END\n" + +echo "Done running model at $(date)" \ No newline at end of file diff --git a/simulation/run_seg_pipeline.sh b/simulation/run_seg_pipeline.sh deleted file mode 100644 index 1ced368..0000000 --- a/simulation/run_seg_pipeline.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -#SBATCH -N 1 -#SBATCH -n 1 -#SBATCH --qos=normal -#SBATCH --job-name=act-orig-pipeline -#SBATCH --output=output/run_orig_pipeline.out -#SBATCH --time 0-12:00 - - - -START=$(date) -python generate_target_traces.py -python generate_traces.py build -sbatch --wait batch_generate_traces.sh -python generate_arma_stats.py -python run_simulation.py -python analyze_res.py -python plot_fi.py -python plot_learned_parameters.py -END=$(date) - -printf "Start: $START \nEnd: $END\n" - -echo "Done running model at $(date)" \ No newline at end of file diff --git a/simulation/run_simulation.py b/simulation/run_simulation.py index 63c6be6..5bccc68 100644 --- a/simulation/run_simulation.py +++ b/simulation/run_simulation.py @@ -2,6 +2,9 @@ import sys sys.path.append("../") from act import simulator +import meta_sweep if __name__ == "__main__": + if '--sweep' in sys.argv: + selected_config = meta_sweep.get_meta_params_for_sweep() p = simulator.run(selected_config, subprocess=False) diff --git a/simulation/run_sweep.sh b/simulation/run_sweep.sh new file mode 100644 index 0000000..d478e68 --- /dev/null +++ b/simulation/run_sweep.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#SBATCH -N 1 +#SBATCH -n 1 +#SBATCH --qos=normal +#SBATCH --job-name=act-orig-pipeline +#SBATCH --output=output/run_pipeline.out +#SBATCH --time 0-12:00 + + + +START=$(date) +python run_full_pipeline.py --sweep +END=$(date) + +printf "Start: $START \nEnd: $END\n" + +echo "Done running model at $(date)" \ No newline at end of file diff --git a/simulation/simulation_configs.py b/simulation/simulation_configs.py index 3089a2c..5f8b001 100644 --- a/simulation/simulation_configs.py +++ b/simulation/simulation_configs.py @@ -82,6 +82,7 @@ "num_amps_to_match": 1, "num_epochs": 10, "random_seed": 42, + "generate_arma": True, "skip_match_voltage": True, "parametric_distribution": { # sample the parameter space for training if n_slices is > 1 "n_slices": 5, @@ -205,6 +206,7 @@ "num_amps_to_match": 12, "num_epochs": 10, "random_seed": 42, + "generate_arma": True, "skip_match_voltage": True, "use_random_forest": True, "parametric_distribution": { # sample the parameter space for training if n_slices is > 1 @@ -330,6 +332,7 @@ "num_amps_to_match": 1, "num_epochs": 10, "random_seed": 42, + "generate_arma": False, "skip_match_voltage": True, "parametric_distribution": { # sample the parameter space for training if n_slices is > 1 "n_slices": 5, @@ -453,6 +456,7 @@ "num_amps_to_match": 12, "num_epochs": 10, "random_seed": 42, + "generate_arma": False, "skip_match_voltage": True, "use_random_forest": True, "parametric_distribution": { # sample the parameter space for training if n_slices is > 1 @@ -571,6 +575,7 @@ "num_amps_to_match": 1, "num_epochs": 10, "random_seed": 42, + "generate_arma": False, "skip_match_voltage": True, "parametric_distribution": { # sample the parameter space for training if n_slices is > 1 "n_slices": 5, @@ -664,6 +669,7 @@ "num_amps_to_match": 12, "num_epochs": 10, "random_seed": 42, + "generate_arma": False, "skip_match_voltage": True, "use_random_forest": True, "parametric_distribution": { # sample the parameter space for training if n_slices is > 1 @@ -766,7 +772,8 @@ "num_repeats": 1, "num_amps_to_match": 1, "num_epochs": 10, - "random_seed": 42, + "random_seed": 45, + "generate_arma": False, "skip_match_voltage": True, "parametric_distribution": { # sample the parameter space for training if n_slices is > 1 "n_slices": 2, @@ -861,11 +868,12 @@ "num_repeats": 1, "num_amps_to_match": 12, "num_epochs": 10, - "random_seed": 42, + "random_seed": 53, + "generate_arma": False, "skip_match_voltage": True, "use_random_forest": True, "parametric_distribution": { # sample the parameter space for training if n_slices is > 1 - "n_slices": 3, + "n_slices": 2, }, "decimate_factor": 10, }, @@ -898,4 +906,4 @@ # SELECTED_CONFIG # =================================================================================================================== # =================================================================================================================== -selected_config = Burster_S3_orig +selected_config = LA_A_seg diff --git a/simulation/slurm-6441.out b/simulation/slurm-6441.out deleted file mode 100644 index 33de957..0000000 --- a/simulation/slurm-6441.out +++ /dev/null @@ -1,772 +0,0 @@ -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/torch/__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ../torch/csrc/tensor/python_tensor.cpp:451.) - _C._set_default_tensor_type(t) -Warning: no DISPLAY environment variable. ---No graphics will be displayed. -/home/mwsrgf/proj/ACT/simulation -Mod files: "temp_modfiles/temp_modfiles/capool.mod" "temp_modfiles/temp_modfiles/cas.mod" "temp_modfiles/temp_modfiles/cat.mod" "temp_modfiles/temp_modfiles/inhsyn.mod" "temp_modfiles/temp_modfiles/ka.mod" "temp_modfiles/temp_modfiles/kca.mod" "temp_modfiles/temp_modfiles/kdr.mod" "temp_modfiles/temp_modfiles/leak.mod" "temp_modfiles/temp_modfiles/na.mod" - -Creating 'x86_64' directory for .o files. - - -> Compiling mod_func.cpp - -> NMODL ../temp_modfiles/capool.mod - -> NMODL ../temp_modfiles/cas.mod - -> NMODL ../temp_modfiles/cat.mod -Translating capool.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/capool.c - -> NMODL ../temp_modfiles/inhsyn.mod -Translating cas.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/cas.c -Translating cat.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/cat.c -Thread Safe -Thread Safe -Thread Safe - -> NMODL ../temp_modfiles/ka.mod -Translating inhsyn.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/inhsyn.c - -> NMODL ../temp_modfiles/kca.mod - -> NMODL ../temp_modfiles/kdr.mod -Thread Safe -Translating ka.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/ka.c - -> NMODL ../temp_modfiles/leak.mod -Thread Safe -Translating kca.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/kca.c -Translating kdr.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/kdr.c -Thread Safe -Thread Safe - -> NMODL ../temp_modfiles/na.mod -Translating leak.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/leak.c -Thread Safe - -> Compiling capool.c - -> Compiling cas.c - -> Compiling cat.c -Translating na.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/na.c -Thread Safe - -> Compiling inhsyn.c - -> Compiling ka.c - -> Compiling kca.c - -> Compiling kdr.c - -> Compiling leak.c - -> Compiling na.c - => LINKING shared library ./libnrnmech.so - => LINKING executable ./special LDFLAGS are: -pthread -Successfully created x86_64/special -generating traces... - -(2024-02-18 22:45:48.151818)-[START] -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[0].soma[0].gbar_leak = 0.00003538 -Setting Burster[0].soma[0].cm = 1.52762500 -Generating trace for 0.0 pA -h.celsius set to 31.0 -Generating trace for 500.0 pA -h.celsius set to 31.0 -Generating trace for 1000.0 pA -h.celsius set to 31.0 -Generating trace for 1500.0 pA -h.celsius set to 31.0 -Generating trace for 2000.0 pA -h.celsius set to 31.0 -h.celsius set to 31.0 -Saving target voltage data to: ./output/Burster_orig_2-slice_42-seed/target/target_v.json -done -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/torch/__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ../torch/csrc/tensor/python_tensor.cpp:451.) - _C._set_default_tensor_type(t) -numprocs=1 -WARNING:root:No edges have been made for this network, skipping saving of edges file. -/home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms -Mod files: "./capool.mod" "./cas.mod" "./cat.mod" "./inhsyn.mod" "./ka.mod" "./kca.mod" "./kdr.mod" "./leak.mod" "./na.mod" - - -> Compiling mod_func.cpp - -> NMODL ../capool.mod - -> NMODL ../cas.mod - -> NMODL ../cat.mod -Translating capool.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/capool.c -Translating cas.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/cas.c - -> NMODL ../inhsyn.mod -Translating cat.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/cat.c -Thread Safe -Thread Safe -Thread Safe - -> NMODL ../ka.mod -Translating inhsyn.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/inhsyn.c - -> NMODL ../kca.mod - -> NMODL ../kdr.mod -Thread Safe - -> NMODL ../leak.mod -Translating ka.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/ka.c -Translating kca.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/kca.c -Translating kdr.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/kdr.c -Thread Safe -Thread Safe -Thread Safe - -> NMODL ../na.mod -Translating leak.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/leak.c - -> Compiling capool.c -Thread Safe - -> Compiling cas.c - -> Compiling cat.c -Translating na.mod into /home/mwsrgf/proj/ACT/simulation/output/Burster_orig_2-slice_42-seed/sim_data/components/mechanisms/x86_64/na.c -Thread Safe - -> Compiling inhsyn.c - -> Compiling ka.c - -> Compiling kca.c - -> Compiling kdr.c - -> Compiling leak.c - -> Compiling na.c - => LINKING shared library ./libnrnmech.so -Successfully created x86_64/special -/home/mwsrgf/proj/ACT/simulation -Building Network -Setting celsius to default value of 31.0 -Number of cells to be generated: 320 (5 amps * 64 cells per amp (parameters ^ splits)) -Submitted batch job 6442 -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/torch/__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ../torch/csrc/tensor/python_tensor.cpp:451.) - _C._set_default_tensor_type(t) -numprocs=1 -loading large file (./output/Burster_orig_2-slice_42-seed/sim_data/output/v_report.h5) -decimate_factor set - reducing dataset by 10x -ARIMA order set to (4, 0, 4) -processing cell 115/320 -processing cell 116/320 -processing cell 161/320 -processing cell 162/320 -processing cell 75/320 -processing cell 76/320 -processing cell 171/320 -processing cell 172/320 -processing cell 121/320 -processing cell 122/320 -processing cell 187/320 -processing cell 188/320 -processing cell 109/320 -processing cell 110/320 -processing cell 245/320 -processing cell 246/320 -processing cell 101/320 -processing cell 102/320 -processing cell 137/320 -processing cell 138/320 -processing cell 233/320 -processing cell 234/320 -processing cell 113/320 -processing cell 114/320 -processing cell 165/320 -processing cell 166/320 -processing cell 119/320 -processing cell 120/320 -processing cell 189/320 -processing cell 190/320 -processing cell 127/320 -processing cell 128/320 -processing cell 173/320 -processing cell 174/320 -processing cell 91/320 -processing cell 92/320 -processing cell 159/320 -processing cell 160/320 -processing cell 43/320 -processing cell 44/320 -processing cell 207/320 -processing cell 208/320 -processing cell 69/320 -processing cell 70/320 -processing cell 169/320 -processing cell 170/320 -processing cell 47/320 -processing cell 48/320 -processing cell 197/320 -processing cell 198/320 -processing cell 97/320 -processing cell 98/320 -processing cell 199/320 -processing cell 200/320 -processing cell 85/320 -processing cell 86/320 -processing cell 183/320 -processing cell 184/320 -processing cell 125/320 -processing cell 126/320 -processing cell 191/320 -processing cell 192/320 -processing cell 21/320 -processing cell 22/320 -processing cell 215/320 -processing cell 216/320 -processing cell 87/320 -processing cell 88/320 -processing cell 129/320 -processing cell 130/320 -processing cell 219/320 -processing cell 220/320 -processing cell 279/320 -processing cell 280/320 -processing cell 5/320 -processing cell 6/320 -processing cell 193/320 -processing cell 194/320 -processing cell 11/320 -processing cell 12/320 -processing cell 195/320 -processing cell 196/320 -processing cell 37/320 -processing cell 38/320 -processing cell 221/320 -processing cell 222/320 -processing cell 29/320 -processing cell 30/320 -processing cell 237/320 -processing cell 238/320 -processing cell 63/320 -processing cell 64/320 -processing cell 227/320 -processing cell 228/320 -processing cell 19/320 -processing cell 20/320 -processing cell 225/320 -processing cell 226/320 -processing cell 61/320 -processing cell 62/320 -processing cell 149/320 -processing cell 150/320 -processing cell 273/320 -processing cell 274/320 -processing cell 89/320 -processing cell 90/320 -processing cell 209/320 -processing cell 210/320 -processing cell 77/320 -processing cell 78/320 -processing cell 231/320 -processing cell 232/320 -processing cell 123/320 -processing cell 124/320 -processing cell 247/320 -processing cell 248/320 -processing cell 27/320 -processing cell 28/320 -processing cell 217/320 -processing cell 218/320 -processing cell 79/320 -processing cell 80/320 -processing cell 229/320 -processing cell 230/320 -processing cell 33/320 -processing cell 34/320 -processing cell 203/320 -processing cell 204/320 -processing cell 271/320 -processing cell 272/320 -processing cell 73/320 -processing cell 74/320 -processing cell 153/320 -processing cell 154/320 -processing cell 243/320 -processing cell 244/320 -processing cell 303/320 -processing cell 304/320 -processing cell 81/320 -processing cell 82/320 -processing cell 201/320 -processing cell 202/320 -processing cell 287/320 -processing cell 288/320 -processing cell 55/320 -processing cell 56/320 -processing cell 223/320 -processing cell 224/320 -processing cell 67/320 -problem processing cell 66: LU decomposition error. | setting all values to 0.0 -processing cell 68/320 -processing cell 259/320 -processing cell 260/320 -processing cell 31/320 -processing cell 32/320 -processing cell 143/320 -processing cell 144/320 -processing cell 265/320 -processing cell 266/320 -processing cell 23/320 -processing cell 24/320 -processing cell 139/320 -processing cell 140/320 -processing cell 235/320 -processing cell 236/320 -processing cell 293/320 -processing cell 294/320 -processing cell 17/320 -processing cell 18/320 -processing cell 135/320 -processing cell 136/320 -processing cell 239/320 -processing cell 240/320 -processing cell 315/320 -processing cell 316/320 -processing cell 41/320 -processing cell 42/320 -processing cell 177/320 -processing cell 178/320 -processing cell 283/320 -processing cell 284/320 -processing cell 83/320 -processing cell 84/320 -processing cell 145/320 -processing cell 146/320 -processing cell 277/320 -processing cell 278/320 -processing cell 3/320 -processing cell 4/320 -processing cell 249/320 -processing cell 250/320 -processing cell 65/320 -processing cell 66/320 -processing cell 181/320 -processing cell 182/320 -processing cell 297/320 -processing cell 298/320 -processing cell 107/320 -processing cell 108/320 -processing cell 255/320 -processing cell 256/320 -processing cell 35/320 -processing cell 36/320 -processing cell 141/320 -processing cell 142/320 -processing cell 261/320 -processing cell 262/320 -processing cell 53/320 -processing cell 54/320 -processing cell 147/320 -processing cell 148/320 -processing cell 257/320 -processing cell 258/320 -processing cell 7/320 -processing cell 8/320 -processing cell 253/320 -processing cell 254/320 -processing cell 45/320 -processing cell 46/320 -processing cell 269/320 -processing cell 270/320 -processing cell 15/320 -processing cell 16/320 -processing cell 185/320 -processing cell 186/320 -processing cell 301/320 -processing cell 302/320 -processing cell 99/320 -processing cell 100/320 -processing cell 151/320 -processing cell 152/320 -processing cell 309/320 -processing cell 310/320 -processing cell 9/320 -processing cell 10/320 -processing cell 275/320 -processing cell 276/320 -processing cell 71/320 -processing cell 72/320 -processing cell 267/320 -processing cell 268/320 -processing cell 13/320 -processing cell 14/320 -processing cell 211/320 -processing cell 212/320 -processing cell 317/320 -processing cell 318/320 -processing cell 95/320 -processing cell 96/320 -processing cell 179/320 -processing cell 180/320 -processing cell 289/320 -processing cell 290/320 -processing cell 39/320 -processing cell 40/320 -processing cell 133/320 -processing cell 134/320 -processing cell 241/320 -processing cell 242/320 -processing cell 307/320 -processing cell 308/320 -processing cell 111/320 -processing cell 112/320 -processing cell 163/320 -processing cell 164/320 -processing cell 285/320 -processing cell 286/320 -processing cell 103/320 -processing cell 104/320 -processing cell 175/320 -processing cell 176/320 -processing cell 291/320 -processing cell 292/320 -processing cell 51/320 -processing cell 52/320 -processing cell 157/320 -processing cell 158/320 -processing cell 281/320 -processing cell 282/320 -processing cell 1/320 -processing cell 2/320 -processing cell 295/320 -processing cell 296/320 -processing cell 59/320 -processing cell 60/320 -processing cell 263/320 -processing cell 264/320 -processing cell 105/320 -processing cell 106/320 -processing cell 205/320 -processing cell 206/320 -processing cell 305/320 -processing cell 306/320 -processing cell 117/320 -processing cell 118/320 -processing cell 167/320 -processing cell 168/320 -processing cell 299/320 -processing cell 300/320 -processing cell 93/320 -processing cell 94/320 -processing cell 213/320 -processing cell 214/320 -processing cell 313/320 -processing cell 314/320 -processing cell 57/320 -processing cell 58/320 -processing cell 155/320 -processing cell 156/320 -processing cell 319/320 -processing cell 320/320 -processing cell 25/320 -processing cell 26/320 -processing cell 131/320 -processing cell 132/320 -processing cell 311/320 -processing cell 312/320 -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/torch/__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ../torch/csrc/tensor/python_tensor.cpp:451.) - _C._set_default_tensor_type(t) -Warning: no DISPLAY environment variable. ---No graphics will be displayed. -/home/mwsrgf/proj/ACT/simulation -Mod files: "temp_modfiles/temp_modfiles/capool.mod" "temp_modfiles/temp_modfiles/cas.mod" "temp_modfiles/temp_modfiles/cat.mod" "temp_modfiles/temp_modfiles/inhsyn.mod" "temp_modfiles/temp_modfiles/ka.mod" "temp_modfiles/temp_modfiles/kca.mod" "temp_modfiles/temp_modfiles/kdr.mod" "temp_modfiles/temp_modfiles/leak.mod" "temp_modfiles/temp_modfiles/na.mod" - -Creating 'x86_64' directory for .o files. - - -> Compiling mod_func.cpp - -> NMODL ../temp_modfiles/capool.mod - -> NMODL ../temp_modfiles/cas.mod - -> NMODL ../temp_modfiles/cat.mod -Translating capool.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/capool.c - -> NMODL ../temp_modfiles/inhsyn.mod -Translating cas.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/cas.c -Translating cat.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/cat.c -Thread Safe -Thread Safe -Thread Safe - -> NMODL ../temp_modfiles/ka.mod -Translating inhsyn.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/inhsyn.c - -> NMODL ../temp_modfiles/kca.mod -Thread Safe - -> NMODL ../temp_modfiles/kdr.mod -Translating ka.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/ka.c - -> NMODL ../temp_modfiles/leak.mod -Thread Safe -Translating kca.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/kca.c -Translating kdr.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/kdr.c -Thread Safe - -> NMODL ../temp_modfiles/na.mod -Thread Safe -Translating leak.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/leak.c -Thread Safe - -> Compiling capool.c - -> Compiling cas.c - -> Compiling cat.c -Translating na.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/na.c -Thread Safe - -> Compiling inhsyn.c - -> Compiling ka.c - -> Compiling kca.c - -> Compiling kdr.c - -> Compiling leak.c - -> Compiling na.c - => LINKING shared library ./libnrnmech.so - => LINKING executable ./special LDFLAGS are: -pthread -Successfully created x86_64/special -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/torch/utils/_device.py:77: UserWarning: The use of `x.T` on tensors of dimension other than 2 to reverse their shape is deprecated and it will throw an error in a future release. Consider `x.mT` to transpose batches of matrices or `x.permute(*torch.arange(x.ndim - 1, -1, -1))` to reverse the dimensions of a tensor. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3614.) - return func(*args, **kwargs) -/home/mwsrgf/proj/ACT/simulation/../act/utils.py:936: RuntimeWarning: Mean of empty slice. - amplitude = x[peaks].mean() -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/numpy/core/_methods.py:129: RuntimeWarning: invalid value encountered in divide - ret = ret.dtype.type(ret / rcount) - -(2024-02-18 22:47:26.890992)-[START] -(2024-02-18 22:47:26.891026)-[INFO]: Number of amplitudes: 5 -Loading ./output/Burster_orig_2-slice_42-seed/target/target_v.json for target traces -decimate_factor set - reducing generated target voltage by 10x -(2024-02-18 22:47:27.192908)-[INFO]: Target voltage shape: torch.Size([5, 1000]) -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[0].soma[0].gbar_leak = 0.00003538 -Setting Burster[0].soma[0].cm = 1.52762500 -Extracting first 10 spikes for summary features -loading large file (./output/Burster_orig_2-slice_42-seed/sim_data/output/v_report.h5) -decimate_factor set - reducing dataset by 10x -224/320 spiking traces extracted. -Dropping 188 traces, mean value >-50 between 550:750ms -Overriding model class to RandomForest -resampling of traces not needed, same shape as target -fitting random forest -Done fitting random forest -Feature importance -Avg Max Spike Height : 27.66 -Avg Min Spike Height : 17.38 -Spike 2 time : 11.12 -Interspike Interval : 10.69 -Spike 1 time : 7.98 -Num Spikes : 7.59 -Spike 4 time : 5.93 -Spike 3 time : 4.52 -Spike 8 time : 1.29 -Spike 9 time : 1.24 -Spike 5 time : 1.22 -Spike 10 time : 1.19 -Spike 6 time : 1.11 -Spike 7 time : 1.1 -Amps supplied: [0.0, 0.5, 1.0, 1.5, 2.0] -Amps predicted: [1.2613682746887207, 1.2623332738876343, 1.2595967054367065, 1.2493733167648315, 1.2554583549499512] -Amps error: [-1.2613682746887207, -0.7623332738876343, -0.25959670543670654, 0.25062668323516846, 0.7445416450500488] -Amps error sum: -1.2881299257278442 -writing training run stats for repeat 1 -done -1 predictions: [[0.18810045719146729, 0.1242673322558403, 0.008672761730849743, 0.0033556190319359303, 0.10391533374786377, 0.02894076146185398], [0.17917466163635254, 0.1292133331298828, 0.008972762152552605, 0.003495618933811784, 0.0945313349366188, 0.030052760615944862], [0.17763373255729675, 0.1311986744403839, 0.009088762104511261, 0.0035256189294159412, 0.09398733079433441, 0.030204761773347855], [0.1702098548412323, 0.13502933084964752, 0.009320762008428574, 0.003619618946686387, 0.08555533736944199, 0.03111676126718521], [0.17104965448379517, 0.13550333678722382, 0.00929276179522276, 0.0035996190272271633, 0.08739133179187775, 0.030964761972427368]] -Calculating error... -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -Repeat 1 mean: [0.17723367214202881, 0.13104240149259566, 0.009069561958312988, 0.0035192189738154412, 0.09307613372802734, 0.030255961418151855] | variance: [4.1918117947190576e-05, 1.7013404974699498e-05, 5.602178017975745e-08, 8.78143708878728e-09, 4.1863099728343126e-05, 6.034075001057348e-07] -All predictions: [[0.18810045719146729, 0.1242673322558403, 0.008672761730849743, 0.0033556190319359303, 0.10391533374786377, 0.02894076146185398], [0.17917466163635254, 0.1292133331298828, 0.008972762152552605, 0.003495618933811784, 0.0945313349366188, 0.030052760615944862], [0.17763373255729675, 0.1311986744403839, 0.009088762104511261, 0.0035256189294159412, 0.09398733079433441, 0.030204761773347855], [0.1702098548412323, 0.13502933084964752, 0.009320762008428574, 0.003619618946686387, 0.08555533736944199, 0.03111676126718521], [0.17104965448379517, 0.13550333678722382, 0.00929276179522276, 0.0035996190272271633, 0.08739133179187775, 0.030964761972427368]] -Err per prediction: [148.31556701660156, 153.6968231201172, 154.41632080078125, 160.08599853515625, 158.44515991210938] -FI Err per prediction: [3.2, 2.4, 3.2, 2.8, 2.8] -Amplitude/Frequency err per prediction [264.0, 234.0, 220.0, 194.0, 208.0] -Best prediction: [0.17917466163635254, 0.1292133331298828, 0.008972762152552605, 0.003495618933811784, 0.0945313349366188, 0.030052760615944862] -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[1].soma[0].gbar_leak = 0.00003538 -Setting Burster[1].soma[0].cm = 1.52762500 -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -h.celsius set to 31.0 -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[2].soma[0].gbar_leak = 0.00003538 -Setting Burster[2].soma[0].cm = 1.52762500 -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[3].soma[0].gbar_leak = 0.00003538 -Setting Burster[3].soma[0].cm = 1.52762500 -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[4].soma[0].gbar_leak = 0.00003538 -Setting Burster[4].soma[0].cm = 1.52762500 -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[5].soma[0].gbar_leak = 0.00003538 -Setting Burster[5].soma[0].cm = 1.52762500 -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[6].soma[0].gbar_leak = 0.00003538 -Setting Burster[6].soma[0].cm = 1.52762500 -h.celsius set to 31.0 -decimate_factor set - reducing sims voltage by 10x -/home/mwsrgf/proj/ACT/simulation/analyze_res.py:6: DeprecationWarning: -Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0), -(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries) -but was not found to be installed on your system. -If this would cause problems for you, -please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466 - - import pandas as pd -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/torch/__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ../torch/csrc/tensor/python_tensor.cpp:451.) - _C._set_default_tensor_type(t) -Warning: no DISPLAY environment variable. ---No graphics will be displayed. -./output/Burster_orig_2-slice_42-seed/ -Med MSE: 125.1478 (32.1713) -Med Corr: 0.4629 (0.2671) - -Predicted values: - gbar_na gbar_kdr gbar_cas gbar_cat gbar_ka gbar_kca -0 0.179175 0.129213 0.008973 0.003496 0.094531 0.030053 -Target values: - gbar_na gbar_kdr gbar_cas gbar_cat gbar_ka gbar_kca -0 0.13 0.1 0.01 0.005 0.17 0.02 -Error: - gbar_na gbar_kdr gbar_cas gbar_cat gbar_ka gbar_kca -0 0.049175 0.029213 -0.001027 -0.001504 -0.075469 0.010053 - -Pred MAE: 0.0277 - -Model ACT-Original Passive properties: -{ - "leak_conductance_variable": "gbar_leak", - "leak_reversal_variable": "eleak", - "r_in": 50.117835998535156, - "tau": 26.1, - "v_rest": -52.25846481323242 -} ----------- - - -User Trace Passive properties: -{ - "v_rest": -49, - "r_in": 90, - "tau": 43.175, - "leak_conductance_variable": "gbar_leak", - "leak_reversal_variable": "eleak" -} ----------- - - -Passive properties errror -v_rest: -3.26 -r_in: -39.88 -tau: -17.07 ----------- - -target spikes: tensor([ 5., 7., 8., 10., 11.]) -simulated spikes: tensor([ 8., 7., 7., 9., 10.]) -diff: tensor([ 3., 0., -1., -1., -1.]) -Simulated and target FI curve error [SUM((simulated-target)/target)/n]: 1.2 -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/torch/__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ../torch/csrc/tensor/python_tensor.cpp:451.) - _C._set_default_tensor_type(t) -Warning: no DISPLAY environment variable. ---No graphics will be displayed. -./output/Burster_orig_2-slice_42-seed/model_data/Burster_orig_2-slice_42-seed_FI.png -Model ACT-Original (err: 2.4): [ 0. 500. 1000. 1500. 2000.] pA : [16. 14. 14. 18. 20.] Hz -User Trace: [ 0. 500. 1000. 1500. 2000.] pA : [10. 14. 16. 20. 22.] Hz -Warning: no DISPLAY environment variable. ---No graphics will be displayed. -/home/mwsrgf/act-venv/lib64/python3.9/site-packages/torch/__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ../torch/csrc/tensor/python_tensor.cpp:451.) - _C._set_default_tensor_type(t) -/home/mwsrgf/proj/ACT/simulation -Mod files: "temp_modfiles/temp_modfiles/capool.mod" "temp_modfiles/temp_modfiles/cas.mod" "temp_modfiles/temp_modfiles/cat.mod" "temp_modfiles/temp_modfiles/inhsyn.mod" "temp_modfiles/temp_modfiles/ka.mod" "temp_modfiles/temp_modfiles/kca.mod" "temp_modfiles/temp_modfiles/kdr.mod" "temp_modfiles/temp_modfiles/leak.mod" "temp_modfiles/temp_modfiles/na.mod" - -Creating 'x86_64' directory for .o files. - - -> Compiling mod_func.cpp - -> NMODL ../temp_modfiles/capool.mod - -> NMODL ../temp_modfiles/cas.mod - -> NMODL ../temp_modfiles/cat.mod - -> NMODL ../temp_modfiles/inhsyn.mod -Translating cas.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/cas.c -Translating capool.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/capool.c -Translating cat.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/cat.c -Thread Safe -Thread Safe -Thread Safe - -> NMODL ../temp_modfiles/ka.mod -Translating inhsyn.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/inhsyn.c - -> NMODL ../temp_modfiles/kdr.mod - -> NMODL ../temp_modfiles/kca.mod -Thread Safe -Translating ka.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/ka.c - -> NMODL ../temp_modfiles/leak.mod -Thread Safe -Translating kdr.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/kdr.c -Translating kca.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/kca.c -Thread Safe -Thread Safe - -> NMODL ../temp_modfiles/na.mod -Translating leak.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/leak.c -Thread Safe - -> Compiling capool.c - -> Compiling cas.c -Translating na.mod into /home/mwsrgf/proj/ACT/simulation/x86_64/na.c - -> Compiling cat.c -Thread Safe - -> Compiling inhsyn.c - -> Compiling ka.c - -> Compiling kca.c - -> Compiling kdr.c - -> Compiling leak.c - -> Compiling na.c - => LINKING shared library ./libnrnmech.so - => LINKING executable ./special LDFLAGS are: -pthread -Successfully created x86_64/special -Loading ./output/Burster_orig_2-slice_42-seed/target/target_v.json for target traces -loading hoc file ../data/BursterS3/orig/template.hoc -Setting eleak = -49 -Setting Burster[0].soma[0].gbar_leak = 0.00003538 -Setting Burster[0].soma[0].cm = 1.52762500 -Generating trace for 0.0 pA -Setting params: {} -h.celsius set to 31.0 -Generating trace for 500.0 pA -Setting params: {} -h.celsius set to 31.0 -Generating trace for 1000.0 pA -Setting params: {} -h.celsius set to 31.0 -Generating trace for 1500.0 pA -Setting params: {} -h.celsius set to 31.0 -Generating trace for 2000.0 pA -Setting params: {} -h.celsius set to 31.0 -saving fi -Model ACT-Original (err: 0.0): [ 0. 500. 1000. 1500. 2000.] pA : [10. 14. 16. 20. 22.] Hz -User Trace: [ 0. 500. 1000. 1500. 2000.] pA : [10. 14. 16. 20. 22.] Hz -Learned Params -{} - -Target Params -{'gbar_na': 0.13, 'gbar_kdr': 0.1, 'gbar_cas': 0.01, 'gbar_cat': 0.005, 'gbar_ka': 0.17, 'gbar_kca': 0.02} - -Difference -{} - -Difference (percent) -{} - -done -Start: Sun Feb 18 22:45:40 CST 2024 -End: Sun Feb 18 22:48:05 CST 2024 -Done running model at Sun Feb 18 22:48:05 CST 2024