/scripts/EXPERIMENTAL/expcleanup.py

https://github.com/lisa-lab/PLearn · Python · 115 lines · 44 code · 27 blank · 44 comment · 8 complexity · 6ec54d8709267a948372c94ef5ad3e39 MD5 · raw file

  1. #!/usr/bin/env python
  2. # expcleanup.py
  3. # Copyright (C) 2009 Pascal Vincent
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are met:
  6. #
  7. # 1. Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. #
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. #
  14. # 3. The name of the authors may not be used to endorse or promote
  15. # products derived from this software without specific prior written
  16. # permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
  19. # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  21. # NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  23. # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. #
  29. # This file is part of the PLearn library. For more information on the PLearn
  30. # library, go to the PLearn Web site at www.plearn.org
  31. import sys
  32. import os
  33. import os.path
  34. import shutil
  35. def expcleanup(rootdir):
  36. # remove all no loner needed outmat?.pmat
  37. # This is commented out: it's problematic since for now, the outmats are not closed before all
  38. # pretraining is finiched. It is thus problematic to delete them while they're still open by the prg
  39. # and apparently causes a bug while running.
  40. #
  41. # os.system("""sh -c 'PATH=/bin:/usr/bin; find %s -name training_costs_layer_2.pmat -execdir rm -f outmat1.pmat \;' """ % rootdir)
  42. # os.system("""sh -c 'PATH=/bin:/usr/bin; find %s -name training_costs_layer_3.pmat -execdir rm -f outmat2.pmat \;' """ % rootdir)
  43. # search for finished experiments
  44. for dirpath, dirs, files in os.walk(rootdir):
  45. # Now try detecting signature of various experiment types to call appropriate cleanup operation
  46. # 1) newautoencoders experiment
  47. if 'tmpstats.txt' in files and 'global_stats.pmat' in files and 'Split0' in dirs \
  48. and os.path.exists(os.path.join(dirpath,'Split0/LearnerExpdir/Strat0/Trials0/Split0/LearnerExpdir/training_costs_layer_1.pmat')):
  49. cleanup_newautoencoders_exp(dirpath)
  50. print "All done."
  51. def cleanup_newautoencoders_exp(dirpath):
  52. print
  53. print "************************************************"
  54. print "*** Cleaning up "+dirpath+"***"
  55. # move useful stuff out of srcdir and into destdir
  56. srcdir = os.path.join(dirpath,'Split0/LearnerExpdir/Strat0/Trials0/Split0/LearnerExpdir')
  57. destdir = os.path.join(dirpath,'Split0/LearnerExpdir')
  58. useful_files = [
  59. "learner.psave",
  60. "training_costs_layer_1.pmat",
  61. "training_costs_layer_1.pmat.metadata",
  62. "training_costs_layer_2.pmat",
  63. "training_costs_layer_2.pmat.metadata",
  64. "training_costs_layer_3.pmat",
  65. "training_costs_layer_3.pmat.metadata"
  66. ]
  67. # move those files to destdir
  68. for filename in useful_files:
  69. srcfile = os.path.join(srcdir,filename)
  70. dest = os.path.join(destdir,filename)
  71. if os.path.exists(srcfile):
  72. print "* moving",srcfile,"->",dest
  73. shutil.move(srcfile, dest)
  74. # remove the Split0/LearnerExpdir/Strat0 subdirectory
  75. dirtoremove = os.path.join(dirpath,'Split0/LearnerExpdir/Strat0')
  76. print '* removing ',dirtoremove
  77. shutil.rmtree(dirtoremove, True)
  78. print
  79. # main script:
  80. if len(sys.argv)!=2:
  81. print """
  82. Usage: expcleanup.py dirname
  83. Will attempt to free some disk space in all experiments contained in dirname
  84. removing unnecessary subdirectories (possibly after having relocated useful files)
  85. """
  86. sys.exit()
  87. expcleanup(sys.argv[1])