Repository: confident-ai/deepeval
Issue: `IndexError` when simulating many conversations
Root cause: Resource Mishandling

**Describe the bug**
There's a little bug in the progress bar utils that was causing conversation simulations to fail. Specifically, pbar_id was being treated as a list index rather than an id, but the list shrinks as conversations complete, so I was getting IndexErrors.

There's a quick fix in PR #1917, but I don't know if it changes other behavior unrelated to conversation simulation.

**To Reproduce**
Steps to reproduce the behavior:
- Simulate a bunch of conversations at once.
- After some complete, it'll likely throw an index error.

**Expected behavior**
All conversations should complete simulation successfully.

**Screenshots**
```
  File "[venv]/lib/python3.13/site-packages/deepeval/simulator/conversation_simulator.py", line 124, in _a_simulate
    self.simulated_conversations = await asyncio.gather(*tasks)
  File "[venv]/lib/python3.13/site-packages/deepeval/simulator/conversation_simulator.py", line 112, in simulate_conversations
    return await self._a_simulate_single_conversation(
    ...<5 lines>...
  File "[venv]/lib/python3.13/site-packages/deepeval/simulator/conversation_simulator.py", line 258, in _a_simulate_single_conversation
    stop_conversation = await self.a_stop_conversation(
        turns, golden.expected_outcome, progress, pbar_turns_id
    )
  File "[venv]/lib/python3.13/site-packages/deepeval/simulator/conversation_simulator.py", line 366, in a_stop_conversation
    update_pbar(
        progress,
        pbar_turns_id,
        advance_to_end=is_complete.is_complete,
    )
  File "[venv]/lib/python3.13/site-packages/deepeval/utils.py", line 490, in update_pbar
    advance = progress.tasks[pbar_id].remaining if advance_to_end else advance
IndexError: list index out of range
```


I got same error here, if have more than 1 golden

> simulator.simulate(conversational_goldens=dataset.goldens)

@davizucon @jdcc-betterup Are there any example configs you can provide. How you defined your model callback, how many goldens, if async mode was toggled, DeepEval version. I am unable to reproduce the error.

Wondering if you are also on the latest version of DeepEval?

Hey @kritinv, thanks for your reply,

- deepeval version 3.3.9
- python 3.11.11

Ref: https://deepeval.com/tutorials/medical-chatbot/evaluation#user-simulations
Note: I made some changes to adjust to the new version of deepeval .


```
from typing import List

from deepeval.dataset import ConversationalGolden
from deepeval.dataset import EvaluationDataset
from deepeval.simulator import ConversationSimulator
from deepeval.test_case import Turn

llm_local = None

goldens = [
    ConversationalGolden(
        scenario="User with a sore throat asking for paracetamol.",
        expected_outcome="say you are good!",
    ),
    ConversationalGolden(
        scenario="Frustrated user looking to rebook their appointment.",
        expected_outcome="say you are good!",
    ),
    ConversationalGolden(
        scenario="User just looking to talk to somebody.",
        expected_outcome="say you are good!"
    )
]

dataset = EvaluationDataset(goldens=goldens)


def model_callback(input, turns: List[Turn], thread_id: str) -> Turn:
    return Turn(role="assistant", content="you are good!")


simulator = ConversationSimulator(model_callback=model_callback, simulator_model=llm_local, max_concurrent=1)
test_cases = simulator.simulate(conversational_goldens=dataset.goldens, max_turns=12)

```

@davizucon can you try again? I believe latest version 4.3.3 fixed this

Hey @penguine-ip, thanks for the reply.

The same code above was tested in version 3.4.2, changing max_turns to max_user_simulations. It worked, with no errors. 👍 

Thanks!

@penguine-ip I can confirm that this also fixed the issue for me, thanks!
@davizucon Thanks for being more helpful in this thread than I've been!

@jdcc-betterup great closing this now!