# Buggy code
def reproduce(
    cls,
    dvc_dir: str,
    queue: "Queue",
    rev: str,
    cwd: Optional[str] = None,
    name: Optional[str] = None,
) -> Tuple[Optional[str], bool]:
    """Run dvc repro and return the result.

    Returns tuple of (exp_hash, force) where exp_hash is the experiment
        hash (or None on error) and force is a bool specifying whether or
        not this experiment should force overwrite any existing duplicates.
    """
    from dvc.repo.checkout import checkout as dvc_checkout
    from dvc.repo.reproduce import reproduce as dvc_reproduce

    unchanged = []

    queue.put((rev, os.getpid()))

    def filter_pipeline(stages):
        unchanged.extend(
            [stage for stage in stages if isinstance(stage, PipelineStage)]
        )

    result: Optional[str] = None
    repro_force: bool = False

    try:
        dvc = Repo(dvc_dir)
        old_cwd = os.getcwd()
        new_cwd = cwd if cwd else dvc.root_dir
        os.chdir(new_cwd)
        logger.debug("Running repro in '%s'", cwd)

        args_path = os.path.join(dvc.tmp_dir, BaseExecutor.PACKED_ARGS_FILE)
        if os.path.exists(args_path):
            args, kwargs = BaseExecutor.unpack_repro_args(args_path)
            remove(args_path)
        else:
            args = []
            kwargs = {}

        repro_force = kwargs.get("force", False)

        # NOTE: for checkpoint experiments we handle persist outs slightly
        # differently than normal:
        #
        # - checkpoint out may not yet exist if this is the first time this
        #   experiment has been run, this is not an error condition for
        #   experiments
        # - at the start of a repro run, we need to remove the persist out
        #   and restore it to its last known (committed) state (which may
        #   be removed/does not yet exist) so that our executor workspace
        #   is not polluted with the (persistent) out from an unrelated
        #   experiment run
        dvc_checkout(dvc, force=True, quiet=True)

        checkpoint_func = partial(cls.checkpoint_callback, dvc.scm, name)
        stages = dvc_reproduce(
            dvc,
            *args,
            on_unchanged=filter_pipeline,
            checkpoint_func=checkpoint_func,
            **kwargs,
        )

        exp_hash = cls.hash_exp(stages)
        result = exp_hash
        exp_rev = cls.commit(dvc.scm, exp_hash, exp_name=name)
        if dvc.scm.get_ref(EXEC_CHECKPOINT):
            dvc.scm.set_ref(EXEC_CHECKPOINT, exp_rev)
    except UnchangedExperimentError:
        pass
    finally:
        if dvc:
            dvc.scm.close()
        if old_cwd:
            os.chdir(old_cwd)

    # ideally we would return stages here like a normal repro() call, but
    # stages is not currently picklable and cannot be returned across
    # multiprocessing calls
    return result, repro_force


# Traceback (FileNotFoundError)
Adding '.dvc/config.local' to '.dvc/.gitignore'.
Adding '.dvc/tmp' to '.dvc/.gitignore'.
Adding '.dvc/experiments' to '.dvc/.gitignore'.
Adding '.dvc/cache' to '.dvc/.gitignore'.
Check for update is enabled.
assuming default target 'dvc.yaml'.
fetched: [(3,)]
Checking out experiment commit 'e6a4d8123aebe35a19b9e4544e21ac542a10as66'
Patching experiment workspace
Removing '/tmp/tmp8e9_4d6f'
Adding '.dvc/experiments/src/ai/training/.dvc/config.local' to '.dvc/experiments/src/ai/training/.dvc/.gitignore'.
Adding '.dvc/experiments/src/ai/training/.dvc/tmp' to '.dvc/experiments/src/ai/training/.dvc/.gitignore'.
Adding '.dvc/experiments/src/ai/training/.dvc/experiments' to '.dvc/experiments/src/ai/training/.dvc/.gitignore'.
Stashed experiment 'f951c9d' for future execution.
Reproducing experiment revs 'f951c9d'
Checking out experiment commit 'e6a4d8123aebe35a19b9e4544e21ac542a10s166'
Writing '/tmp/tmpmml3mawm/.dvc/config'.
Init local executor in dir '<TemporaryDirectory '/tmp/tmpmml3mawm'>' with baseline 'e6a4d81'.
Writing experiments local config '/tmp/tmpmml3mawm/src/ai/training/.dvc/config.local'
fetched: [(7583,)]
unexpected error - [Errno 2] No such file or directory: '/tmp/tmpmml3mawm/src/ai/training/.dvc/config.local'
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpmml3mawm/src/ai/training/.dvc/config.local'
------------------------------------------------------------
Traceback (most recent call last):
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/main.py", line 90, in main
ret = cmd.run()
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/command/experiments.py", line 469, in run
**self._repro_kwargs,
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 988, in run
return run(self.repo, *args, **kwargs)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/__init__.py", line 60, in wrapper
return f(repo, *args, **kwargs)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/run.py", line 62, in run
target=target, params=params, **kwargs
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 418, in reproduce_one
results = self.reproduce([stash_rev], keep_stash=False)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 38, in wrapper
return f(exp, *args, **kwargs)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 593, in reproduce
checkpoint_reset=checkpoint_reset,
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/executor.py", line 116, in __init__
self._config(cache_dir)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/executor.py", line 127, in _config
with open(local_config, "w") as fobj:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpmml3mawm/src/ai/training/.dvc/config.local'
------------------------------------------------------------
Adding '.dvc/config.local' to '.dvc/.gitignore'.
Adding '.dvc/tmp' to '.dvc/.gitignore'.
Adding '.dvc/experiments' to '.dvc/.gitignore'.
Adding '.dvc/cache' to '.dvc/.gitignore'.
Version info for developers:
DVC version: 1.10.2 (pip)
---------------------------------
Platform: Python 3.6.12 on Linux-5.4.0-48-generic-x86_64-with-debian-buster-sid
Supports: gs, http, https
Cache types: hardlink, symlink
Cache directory: ext4 on /dev/nvme0n1p2
Caches: local
Remotes: local
Workspace directory: ext4 on /dev/nvme0n1p2
Repo: dvc (subdir), git

# Fixed code
def reproduce(
    cls,
    dvc_dir: str,
    queue: "Queue",
    rev: str,
    rel_cwd: Optional[str] = None,
    name: Optional[str] = None,
    log_level: Optional[int] = None,
) -> Tuple[Optional[str], bool]:
    """Run dvc repro and return the result.

    Returns tuple of (exp_hash, force) where exp_hash is the experiment
        hash (or None on error) and force is a bool specifying whether or
        not this experiment should force overwrite any existing duplicates.
    """
    from dvc.repo.checkout import checkout as dvc_checkout
    from dvc.repo.reproduce import reproduce as dvc_reproduce

    unchanged = []

    queue.put((rev, os.getpid()))
    cls._set_log_level(log_level)

    def filter_pipeline(stages):
        unchanged.extend(
            [stage for stage in stages if isinstance(stage, PipelineStage)]
        )

    result: Optional[str] = None
    repro_force: bool = False

    try:
        dvc = Repo(dvc_dir)
        old_cwd = os.getcwd()
        if rel_cwd:
            os.chdir(os.path.join(dvc.root_dir, rel_cwd))
        else:
            os.chdir(dvc.root_dir)
        logger.debug("Running repro in '%s'", os.getcwd())

        args_path = os.path.join(dvc.tmp_dir, BaseExecutor.PACKED_ARGS_FILE)
        if os.path.exists(args_path):
            args, kwargs = BaseExecutor.unpack_repro_args(args_path)
            remove(args_path)
        else:
            args = []
            kwargs = {}

        repro_force = kwargs.get("force", False)

        # NOTE: for checkpoint experiments we handle persist outs slightly
        # differently than normal:
        #
        # - checkpoint out may not yet exist if this is the first time this
        #   experiment has been run, this is not an error condition for
        #   experiments
        # - at the start of a repro run, we need to remove the persist out
        #   and restore it to its last known (committed) state (which may
        #   be removed/does not yet exist) so that our executor workspace
        #   is not polluted with the (persistent) out from an unrelated
        #   experiment run
        dvc_checkout(dvc, force=True, quiet=True)

        checkpoint_func = partial(cls.checkpoint_callback, dvc.scm, name)
        stages = dvc_reproduce(
            dvc,
            *args,
            on_unchanged=filter_pipeline,
            checkpoint_func=checkpoint_func,
            **kwargs,
        )

        exp_hash = cls.hash_exp(stages)
        result = exp_hash
        exp_rev = cls.commit(dvc.scm, exp_hash, exp_name=name)
        if dvc.scm.get_ref(EXEC_CHECKPOINT):
            dvc.scm.set_ref(EXEC_CHECKPOINT, exp_rev)
    except UnchangedExperimentError:
        pass
    finally:
        if dvc:
            dvc.scm.close()
        if old_cwd:
            os.chdir(old_cwd)

    # ideally we would return stages here like a normal repro() call, but
    # stages is not currently picklable and cannot be returned across
    # multiprocessing calls
    return result, repro_force