2424
2525def create (
2626 temporary_directory : str ,
27- output_directory : Optional [str ],
2827 delete_tmp_folder_after_terminate : bool = True ,
29- delete_output_folder_after_terminate : bool = True ,
3028) -> 'Backend' :
31- context = BackendContext (temporary_directory , output_directory ,
29+ context = BackendContext (temporary_directory ,
3230 delete_tmp_folder_after_terminate ,
33- delete_output_folder_after_terminate ,
3431 )
3532 backend = Backend (context )
3633
@@ -58,28 +55,18 @@ class BackendContext(object):
5855
5956 def __init__ (self ,
6057 temporary_directory : str ,
61- output_directory : Optional [str ],
6258 delete_tmp_folder_after_terminate : bool ,
63- delete_output_folder_after_terminate : bool ,
6459 ):
6560
66- # Check that the names of tmp_dir and output_dir is not the same.
67- if temporary_directory == output_directory and temporary_directory is not None :
68- raise ValueError ("The temporary and the output directory "
69- "must be different." )
70-
7161 self .delete_tmp_folder_after_terminate = delete_tmp_folder_after_terminate
72- self .delete_output_folder_after_terminate = delete_output_folder_after_terminate
7362 # attributes to check that directories were created by autosklearn.
7463 self ._tmp_dir_created = False
75- self ._output_dir_created = False
7664
7765 self ._temporary_directory = (
7866 get_randomized_directory_name (
7967 temporary_directory = temporary_directory ,
8068 )
8169 )
82- self ._output_directory = output_directory
8370 # Auto-Sklearn logs through the use of a PicklableClientLogger
8471 # For this reason we need a port to communicate with the server
8572 # When the backend is created, this port is not available
@@ -94,14 +81,6 @@ def setup_logger(self, port: int) -> None:
9481 port = port ,
9582 )
9683
97- @property
98- def output_directory (self ) -> Optional [str ]:
99- if self ._output_directory is not None :
100- # make sure that tilde does not appear on the path.
101- return os .path .expanduser (os .path .expandvars (self ._output_directory ))
102- else :
103- return None
104-
10584 @property
10685 def temporary_directory (self ) -> str :
10786 # make sure that tilde does not appear on the path.
@@ -112,29 +91,7 @@ def create_directories(self) -> None:
11291 os .makedirs (self .temporary_directory )
11392 self ._tmp_dir_created = True
11493
115- # Exception is raised if self.output_directory already exists.
116- if self .output_directory is not None :
117- os .makedirs (self .output_directory )
118- self ._output_dir_created = True
119-
12094 def delete_directories (self , force : bool = True ) -> None :
121- if self .output_directory and (self .delete_output_folder_after_terminate or force ):
122- if self ._output_dir_created is False :
123- raise ValueError ("Failed to delete output dir: %s because auto-sklearn did not "
124- "create it. Please make sure that the specified output dir does "
125- "not exist when instantiating auto-sklearn."
126- % self .output_directory )
127- try :
128- shutil .rmtree (self .output_directory )
129- except Exception :
130- try :
131- if self ._logger is not None :
132- self ._logger .warning ("Could not delete output dir: %s" %
133- self .output_directory )
134- else :
135- print ("Could not delete output dir: %s" % self .output_directory )
136- except Exception :
137- print ("Could not delete output dir: %s" % self .output_directory )
13895
13996 if self .delete_tmp_folder_after_terminate or force :
14097 if self ._tmp_dir_created is False :
@@ -175,10 +132,6 @@ def __init__(self, context: BackendContext):
175132 os .makedirs (self .temporary_directory )
176133 except Exception :
177134 pass
178- # This does not have to exist or be specified
179- if self .output_directory is not None :
180- if not os .path .exists (self .output_directory ):
181- raise ValueError ("Output directory %s does not exist." % self .output_directory )
182135
183136 self .internals_directory = os .path .join (self .temporary_directory , ".auto-sklearn" )
184137 self ._make_internals_directory ()
@@ -190,10 +143,6 @@ def setup_logger(self, port: int) -> None:
190143 )
191144 self .context .setup_logger (port )
192145
193- @property
194- def output_directory (self ) -> Optional [str ]:
195- return self .context .output_directory
196-
197146 @property
198147 def temporary_directory (self ) -> str :
199148 return self .context .temporary_directory
@@ -466,31 +415,6 @@ def get_prediction_filename(self, subset: str,
466415 ) -> str :
467416 return 'predictions_%s_%s_%s_%s.npy' % (subset , automl_seed , idx , budget )
468417
469- def save_predictions_as_txt (self ,
470- predictions : np .ndarray ,
471- subset : str ,
472- idx : int , precision : int ,
473- prefix : Optional [str ] = None ) -> None :
474- if not self .output_directory :
475- return
476- # Write prediction scores in prescribed format
477- filepath = os .path .join (
478- self .output_directory ,
479- ('%s_' % prefix if prefix else '' ) + '%s_%s.predict' % (subset , str (idx )),
480- )
481-
482- format_string = '{:.%dg} ' % precision
483- with tempfile .NamedTemporaryFile ('w' , dir = os .path .dirname (
484- filepath ), delete = False ) as output_file :
485- for row in predictions :
486- if not isinstance (row , np .ndarray ) and not isinstance (row , list ):
487- row = [row ]
488- for val in row :
489- output_file .write (format_string .format (float (val )))
490- output_file .write ('\n ' )
491- tempname = output_file .name
492- os .rename (tempname , filepath )
493-
494418 def write_txt_file (self , filepath : str , data : str , name : str ) -> None :
495419 with tempfile .NamedTemporaryFile ('w' , dir = os .path .dirname (
496420 filepath ), delete = False ) as fh :
0 commit comments