# Cannot apply the first exp after new commit

**URL:** <https://discuss.dvc.org/t/cannot-apply-the-first-exp-after-new-commit/1444>\
**Category:** Questions\
**Created:** [January 2, 2023, 8:44am UTC](https://discuss.dvc.org/t/cannot-apply-the-first-exp-after-new-commit/1444 "2023-01-02T08:44:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolle](https://avatars.discourse-cdn.com/v4/letter/n/8c91f0/32.png) [@Nicolle](https://discuss.dvc.org/u/Nicolle)\
**Post date:** [January 2, 2023, 8:44am UTC](https://discuss.dvc.org/t/cannot-apply-the-first-exp-after-new-commit/1444/1 "2023-01-02T08:44:18Z")

</div>

Hello,

Iv been trying to use dvc to manage my experiments and like it very much so for but I encountered rather unexpected behavior.

Anytime I commit the code, the very first experiment which I performs afterwards cannot be applied to workspace. The command “dvc exp run” will proceed without errors and environment is modified accordingly. But when I change the environment and then try to “dvc exp apply” it back, no changes to the environment are made (again, no errors or warnings). Applying any other experiments works as expected.

The minimal example is the following:

**dvc.yaml:**  
stages:  
main:  
cmd: Rscript src/main.R  
params:  
- par.yaml:  
metrics:  
- out.yaml:  
cache: false

**par.yaml:**  
a: 1  
b: 1  
c: 1  
d: 1

**main.R**  
library(yaml)  
par ← yaml.load\_file(“par.yaml”)  
out ← list(  
perf = par$a \* 1 + par$b \* 0.1 + par$c \* 0.01 + par$d \* 0.001  
)  
print(out)  
write\_yaml(out, “out.yaml”)

However, I believe that the issue may not be with the dvc.yaml but rather in my workflow as the same happens also when creating the environment with “dvc exp init” and when cloning the official example [repo](https://github.com/iterative/example-dvc-experiments). Em I supposed to call some other command after new commit to prime the environment for new experiments? I had not found anything in the reference manual.

Right now I’m sidestepping the issue by running the first experiment twice and disregarding the first one but it is cumbersome for computationally costly experiments.

Thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![pmrowla](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pmrowla](https://discuss.dvc.org/u/pmrowla)\
**Post date:** [January 3, 2023, 2:13am UTC](https://discuss.dvc.org/t/cannot-apply-the-first-exp-after-new-commit/1444/2 "2023-01-03T02:13:55Z")

</div>

> But when I change the environment and then try to “dvc exp apply” it back

Could you please clarify what you are modifying when you “change the environment” before using `dvc exp apply`?

---

<div class="post-metadata">

**Author:** ![Nicolle](https://avatars.discourse-cdn.com/v4/letter/n/8c91f0/32.png) [@Nicolle](https://discuss.dvc.org/u/Nicolle)\
**Post date:** [January 3, 2023, 2:26pm UTC](https://discuss.dvc.org/t/cannot-apply-the-first-exp-after-new-commit/1444/3 "2023-01-03T14:26:24Z")

</div>

Of course. I by that meant modifying the par.yaml either manually or via `-S` option and reruning the model to regenerate outputs. In particular, for the following (slightly modified) setup

**dvc.yaml:**

```auto
stages:
  main:
    cmd: Rscript src/main.R
    deps:
    - src
    params:
    - par.yaml:
    metrics:
    - out.yaml:
        cache: false

```

**main.R:**

```auto
library(yaml)
par <- yaml.load_file("par.yaml")
b <- 9
out <- list(
    perf = par$a * 1 + b * 0.1
)
print(out)
write_yaml(out, "out.yaml")

```

**par.yaml:**  
`a: 9`

I do the following:

- change values of `a` and `b` to 1 to simulate the process of working on both the code and parameters
- commit all
- run `dvc exp run -n exp_a` and observe that perf=1.1 is created as expected
- run `dvc exp run -n exp_b -S "par.yaml:a=2"` and observe that perf=2.1 is created as expected
- run `dvc exp run -n exp_c -S "par.yaml:a=3"` and observe that perf=3.1 is created as expected
- Now I want return to exp\_a. I call `dvc exp apply exp_a`. However, `a` in par.yaml stays at its current value, in this case 3. Interestingly though, the out.yaml gets restored to the correct value of 1.1.
- If I try to apply any other exp, say exp\_b or c, everything works as expected and both par.yaml and out.yaml are restored.

I also tried to perform another experiment (say exp\_0) right before the commit (so that the commit is published with the correct value of out.yaml) In this case, neither par.yaml nor out.yaml is restored when calling `dvc exp apply exp_a`.

Em I using it right? Thank you.

---

<div class="post-metadata">

**Author:** ![pmrowla](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pmrowla](https://discuss.dvc.org/u/pmrowla)\
**Post date:** [January 5, 2023, 5:39am UTC](https://discuss.dvc.org/t/cannot-apply-the-first-exp-after-new-commit/1444/4 "2023-01-05T05:39:01Z")

</div>

I’ve confirmed that I can reproduce the issue, this is a bug in DVC. To clarify, the changes from the first exp are applied except for files where the file in the experiment result is unchanged from the file in the initial git commit. So in your case, the changes for the output `out.yaml` are applied, but since `par.yaml` is unchanged (both the original commit and the experiment result contain `par.yaml:a=2`) `exp apply` is essentially ignoring the params file and does not modify it.

I’ve opened a github issue for this bug, you can subscribe to it for further updates: [exp apply: git-tracked files which are unchanged from HEAD are not reset on apply · Issue #8764 · iterative/dvc · GitHub](https://github.com/iterative/dvc/issues/8764)

---

<div class="post-metadata">

**Author:** ![Nicolle](https://avatars.discourse-cdn.com/v4/letter/n/8c91f0/32.png) [@Nicolle](https://discuss.dvc.org/u/Nicolle)\
**Post date:** [January 5, 2023, 9:26am UTC](https://discuss.dvc.org/t/cannot-apply-the-first-exp-after-new-commit/1444/5 "2023-01-05T09:26:49Z")

</div>

Great, thank you for opening the issue.  
Keep up with the great work, it is pleasure to use DVC.
