<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def retrieve_trace(self, filename=None, dir=None):
 """Retrieves the application trace files for this PE and saves them as a plain text file. An existing file with the same name will be overwritten. Args: filename (str):
 name of the created file. Defaults to `pe_<id>_<timestamp>.trace` where `id` is the PE identifier and `timestamp` is the number of seconds since the Unix epoch, for example ``pe_83_1511995995.trace``. dir (str):
 a valid directory in which to save the file. Defaults to the current directory. Returns: str: the path to the created file, or None if retrieving a job's logs is not supported in the version of streams to which the job is submitted. .. versionadded:: 1.9 """

        if hasattr(self, "applicationTrace") and self.applicationTrace is not None:
            logger.debug("Retrieving PE trace: " + self.applicationTrace)
            if not filename:
                filename = _file_name('pe', self.id, '.trace')
            return self.rest_client._retrieve_file(self.applicationTrace, filename, dir, 'text/plain')

        else:
            return None