-
Notifications
You must be signed in to change notification settings - Fork 2
Bundling wiki instructions + argparse(r) #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f72cc86
2662568
3cdfa42
c5eff34
3526e70
0cdaf24
809de33
d882d8a
5ad31bb
4c53896
17f6247
5d1e462
8db626e
b3daee9
1368ae2
b0a3dc5
a9bbf80
387914b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,4 +129,9 @@ dmypy.json | |
| .pyre/ | ||
|
|
||
| # IDE | ||
| .idea/ | ||
| .idea/ | ||
|
|
||
| # HPC output | ||
| logs/ | ||
| logs/* | ||
| logs/*/* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/bash | ||
|
|
||
| ################ | ||
| # Slurm settings | ||
| ################ | ||
| #SBATCH --job-name=synthwave_preprocessing # Job name | ||
| #SBATCH --mail-type=FAIL # Mail events (NONE, BEGIN, END, FAIL, ALL) | ||
| #SBATCH --mail-type=END | ||
| #SBATCH --mail-user=h.p.rice@leeds.ac.uk # Where to send mail | ||
| #SBATCH --array=1 # Number of runs, --array=1-X will run X jobs (X >= 1) | ||
| #SBATCH --ntasks=1 # Number of tasks to run, change as desired | ||
| #SBATCH --cpus-per-task=8 # Number of CPU cores per task | ||
| #SBATCH --mem=64gb # Job memory request | ||
| #SBATCH --time=01:00:00 # Time limit hrs:min:sec | ||
| #SBATCH --output=logs/logs/batch-%A-%a.out | ||
| #SBATCH --error=logs/errors/batch-%A-%a.err | ||
|
|
||
|
|
||
| echo -e "\nRunning Synthwave pre-processing steps... \n Source data path: $2\n Subset fraction: $4\n Emails to: $6\n Time: $8" | ||
| echo -e "Task $SLURM_JOB_ID" | ||
| echo -e "Running with $SLURM_CPUS_PER_TASK CPU cores, $SLURM_CPUS_ON_NODE CPU cores per node" | ||
| echo -e "Running task $SLURM_ARRAY_TASK_ID of $SLURM_ARRAY_TASK_MAX\n" | ||
|
|
||
| export MAXIT=1 # Testing | ||
|
|
||
| #python src/synthwave/utils/uk/pre_process.py "$2" | ||
| #Rscript src/synthwave/synthesizer/imputation/adults_imputation.R "$2" -f "$4" -n $NCORES -m $MAXIT # Testing | ||
| Rscript src/synthwave/synthesizer/imputation/adults_imputation.R "$2" -f "$4" -n $SLURM_CPUS_PER_TASK -m $MAXIT | ||
| #Rscript src/synthwave/synthesizer/imputation/adults_imputation.R "$2" -f "$4" -n $SLURM_CPUS_ON_NODE -m $MAXIT | ||
| # python src/synthwave/synthesizer/correct_and_train.py "$2" | ||
|
|
||
| # If no errors... | ||
| exit 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Set current time for directory naming | ||
| TIME=`date +%Y_%m_%d_%H_%M_%S` | ||
|
|
||
| # Create these if they don't exist | ||
| mkdir -p logs | ||
| mkdir -p logs/logs | ||
| mkdir -p logs/errors | ||
|
|
||
|
|
||
| sbatch scripts/aire_run.sh -d "$2" -f "$4" -e "$6" -t $TIME | ||
| #bash scripts/aire_run.sh -d "$2" -f "$4" -e "$6" -t $TIME # Testing | ||
|
|
||
| # If no errors... | ||
| exit 0 |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this should stay in wiki |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # HR 15/03/25 Correct and train imputed data | ||
|
|
||
| import os | ||
| import pandas as pd | ||
| from synthwave.synthesizer.postimputation.correction import correct_imputed_data | ||
| from synthwave.synthesizer.uk.generator import Syntets | ||
| import argparse | ||
|
|
||
|
|
||
| def main(data_path, save_path=None): | ||
|
|
||
| if not save_path: | ||
| save_path = os.path.join(data_path, "synthwave", "trained") | ||
|
|
||
| # 1. Correct imputed data | ||
| print("Correcting imputed data...") | ||
| adults = pd.read_csv(os.path.join(data_path, "synthwave", "imputed", "imputed_data.csv"), dtype_backend="pyarrow") | ||
| adults = correct_imputed_data(adults) | ||
| print("Done!") | ||
|
|
||
| # 2. Train model | ||
| print("Creating generator and restructuring data...") | ||
| generator = Syntets(adults) | ||
| generator.split_data() | ||
| generator.restructure_data() | ||
| print("Done!") | ||
|
|
||
| # load dataset | ||
| print("Tidying up child data...") | ||
| children = pd.read_parquet(os.path.join(data_path, "children_non_imputed_middle_fidelity.parquet")).drop(columns=["id_person"]) | ||
|
|
||
| # convert data types | ||
| children[["ordinal_person_age", "category_person_ethnic_group"]] = children[["ordinal_person_age", "category_person_ethnic_group"]].astype("uint8[pyarrow]") | ||
|
|
||
| # drop households with incomplete records | ||
| crooked_records = pd.unique(children[children["category_person_ethnic_group"].isna()]["id_household"]) | ||
| children = children[~children["id_household"].isin(crooked_records)] # NOTE do not drop duplicates ever, this destroys twins | ||
| print("Done!") | ||
|
|
||
| print("Training child data...") | ||
| # children = children.sample(frac=2.0, replace=True) | ||
| generator.train_children(children, verbose=True) | ||
| print("Done!") | ||
|
|
||
| generator.drop_id_columns() # we need ids to learn how children are formed | ||
| generator.locate_degenerate_distributions() | ||
| generator.convert_types() | ||
| generator.init_models(_epochs=1) | ||
| generator.attach_constraints() | ||
| return generator | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| # parser = argparse.ArgumentParser() | ||
| # parser.add_argument("p", type=str, help="Data source path") | ||
| # | ||
| # args = parser.parse_args() | ||
| # data_path = args.p | ||
|
|
||
| # Run main training - popping this out for testing | ||
| data_path = '/home/hpr/data/' | ||
| g = main(data_path) | ||
| print("Running main training...") | ||
| g.train(save_path=data_path) | ||
| print("Done!") |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the approach, but if you plan to use a smaller sample for quick imputation and subsequent training later it will fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependencies in
setup.pyare for the python part only. Using R here is a workaround until we find something better.