Repository navigation
Feature rescoring module and outputting merged results and model fits - #53
Conversation
|
Just noting here that this PR should not be merged before PR #17 is finished |
Bringing #53 up to par with previous rewrite branch commits before making feature changes.
First pass implementation of MAGIC scoring. Lots of old code needs to be updated and redundancies trimmed out. This is taking the basics of PR #17 and putting a weird new spin on them, so this will need testing and critique. See the design document for more deets.
Merging this PR in sync with `runner` to update upstream workflow to match. Otherwise, testing rescoring and network construction is using older functionality.
Now that @AbhirupaGhosh has updated amRdata to handle single member dyads, this commit reworks the draft network to actually show them as features. These do and did get scored previously, but only paired dyads were allowed into the network view.
First pass implementation of MAGIC scoring. Lots of old code needs to be updated and redundancies trimmed out. This is taking the basics of PR #17 and putting a weird new spin on them, so this will need testing and critique. See the design document for more deets.
Merging this PR in sync with `runner` to update upstream workflow to match. Otherwise, testing rescoring and network construction is using older functionality.
Now that @AbhirupaGhosh has updated amRdata to handle single member dyads, this commit reworks the draft network to actually show them as features. These do and did get scored previously, but only paired dyads were allowed into the network view.
Adding the ability for tasks to be split into chunks and computed on separate HPC nodes for Slurm array jobs. task-chunks.R handles the details, workflow.R includes the user-facing implementation. Currently, array jobs require you to plan the array first, then execute (the actual modeling on many workers in an array), and finally collect the results into a single result bundle.
6c1cc34 to
5eb1220
Compare
…into feature-rescoring
readORB first
Primarily updates HPC performance with Slurm arrays. Now spins out jobs more robustly into very large-scale arrays, and when OOM errors pop up (they will), this logs and auto-retries with additional memory for two more retries. Benchmarking with S. sonnei shows great improvements in runtime when scaled up with large arrays. Also some MDR scoring changes, which aren't final and deserve scrutiny.
Wasn't catching false positives for some MDR classes, bug has been relocated outside and removed from the premises.
Updating CV handling so folds can be distributed to individual CPU cores, which benefits some very very very slow MDR models. Adding verbosity handling, changing what "vanilla" refers to and adding a lot more documentation to help users figure out what different parameters do.
With the first run of rescoring, the complete files are generated which can serve as inputs for amRviz.
Drop proportion_outperforming_shuffled .readFitRun no longer needs state/workflow.rds or state/fit-completion.rds
…rd; drop dead .runRecord runModelingWorkflow(threads > 1) built MulticoreParam directly, skipping the Positron/RStudio check that .defaultBPPARAM() has; the choice now lives in .threadsBPPARAM(). The #57 merge (790ab22) had dropped #56's use_sockets guard in test-fit-resume.R and brought back the unused .runRecord().
|
Some small fixes while testing the stack
The only runtime change is which backend |
Keeps both sides' workflow arguments and tests. Array collection now replays the saved rescore_min_seeds (it always used 3), runTaskChunk() uses .threadsBPPARAM() so threads don't fork inside Positron or RStudio, and the collection test checks #53's Parquet rescoring outputs instead of discovery.rds.
Oops. Co-Authored-By: Emily Boyer <130874527+eboyer221@users.noreply.github.com>
Updated version can return for a later PR
Falling back to previous MDR scoring and tuning behavior. These changes deserve greater scrutiny and should be made in a future PR, and these updates are not necessary for v1. Tossing them for now to keep this PR cleaner!
…imization # Conflicts: # R/rescore.R # R/task-chunks.R # R/workflow.R # man/rescoreFeatures.Rd # man/runModelingWorkflow.Rd # tests/testthat/test-workflow-presets.R
HPC + MDR optimization & updated defaults
Adding HPC array support
epbrenner
left a comment
There was a problem hiding this comment.
I think this PR is pretty neat.
Export, feature rescoring, and recreating old amRml's results
This PR adds feature rescoring and recreates three outputs old amRml wrote that we did not:
exportMergedResults()writes our results in old amRml's merged format, which feature rescoring reads. This is a temporary solution, it goes once our column names match old amRml's or the feature rescoring and amRviz columns update.R/feature-rescoring.R, lifted from PR Add function for feature prioritization #17 with one bug fix (below).rescoreFeatures()runs it on a fit.speciescolumn inresults/, arun.jsonwith the run's settings, and saved model fits.Line references are to the original amRml. The feature rescoring code is from PR #17.
Export (
R/export.R)Feature rescoring reads old amRml's merged tables (
all_perf.parquet,all_top_features.parquet), whichmergeMLresults()built from per-model files. Currently we write one table per output instead, so the export rewrites our results in the merged format and feature rescoring runs unchanged. Once the open renames are done (unit/target/encoding,phenotype,labels), feature rescoring can readresults/directly and the export goes.runModelingWorkflow()callsexportMergedResults()(The temporary component) at the end of every run. It writes to<run>/merged/, one file per mode present, with old amRml's file names, columns and column order:vanillaall_perf.parquetall_top_features.parquetstratified_year,stratified_countryyear_perf.parquet,country_perf.parquetyear_top_features.parquet,country_top_features.parquetcross_drugcross_drug_perf.parquetcross_year,cross_countrycross_year_perf.parquet,cross_country_perf.parquetloto,logoLOO_year_perf.parquet,LOO_country_perf.parquetLOO_year_top_features.parquet,LOO_country_top_features.parquetdrug_label=unit,drug_or_class=target,feature_subtype=encoding,strat_value/drug=train_group,strat_value_test/leaveout_strat_value/test_drug=test_group,num_obs_test_data=n_test.shuffled, and every top-features file an integerseed.filename;train_prop,val_propand theprop_vibounds (they return with the three-way split and iterative feature elimination); ourtask_idandauprc.Problems I noticed in
mergeMLresults()that rewrite solves through the design:AMRFinder,COG,Pfam,DefenseCasorAMX-CLArows got NA metadata (R/merge_ml_results.R, lines 375, 407, 472)shuffled_files broke the stratified merge (lines 336-345) and were ignored by the cross and leave-one-out mergesshuffledis a column nowseedin every top-features fileFeature rescoring (
R/feature-rescoring.R,R/rescore.R)R/feature-rescoring.Ris PR #17's lines 1-387 and 702-1414, with one code change, a bug fix:models$summary)minimum_MCC_diffandmaximum_MCC_diffnamed, withNA_real_instead ofNULLbuildFeatureNetwork(),plotFeatureNetworkD3())topFeaturesPerDrugOrClass()andrunFeatureDyadDiscovery(), as in PR Add function for feature prioritization #17. Its other two exports are the network functions above.rescoreFeatures(fit, ...)checks that the fit has fitted vanilla models with real and shuffled labels, and that the ORB hasdyad_feature.parquet. It exports the merged files if they are missing, then runsrunFeatureDyadDiscovery(); its thresholds pass through.... It is a separate file for now so the feature rescoring code changes as little as possible while this PR shows the two connect; it will move intoR/feature-rescoring.Ronce feature rescoring reads our results directly.Recreating old amRml's results
R/merge_ml_results.R, lines 30-115)speciescolumn (the ORB'sdataset_id, e.g.Sfl) in everyresults/tableml_parameters.json: mode,n_fold, split, seed, timestamp (R/generate_matrices_ml.R, lines 1529-1545)run.json: the ORB and manifest, the modes, thresholds, seeds and labels asked for, versions, start and finish times, task counts.<name>_model_fit.rds, one per model, named by its matrix file,shuffled_prefix and seed (R/run_ML.R, lines 845-864)results/models/<task_id>.rds, one per fitted task, with the matrix's feature IDs. A task is one matrix x label kind x seed, so each fitted task is one model, the same unit old amRml savedrun.json, notml_parameters.json: old amRml read its file back as configuration (R/prep_ml.R, lines 20-45). Here its only a recordHow to use it
Verification
species, timings and dates. Every fit was saved, a saved fit reproduces its predictions, and the feature rescoring results are unchanged.Files
R/export.RexportMergedResults(), temporary stopgapR/feature-rescoring.RR/rescore.RrescoreFeatures(), will eventually go inR/feature-rescoring.RR/fit-models.Rspecies,save_fits,run.jsonR/tasks.RexpandTasks()keeps the seeds and labels asked forR/workflow.Rmerged/; passessave_fitsR/arg-checks.R,R/generate-matrices.Rmerged/andrun.jsonare protected outputsR/globals.R,DESCRIPTION,NAMESPACE,man/Future work