Skip to content

Commit 0fcfcb0

Browse files
committed
fix sampling error
1 parent db8839e commit 0fcfcb0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

sotopia/samplers/constraint_based_sampler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,16 @@ def sample(
8787
agents_which_fit_scenario: list[list[str]] = []
8888

8989
if self.env_candidates is None:
90-
self.env_candidates = EnvironmentProfile.all()
90+
env_candidates = EnvironmentProfile.all()
91+
if not env_candidates:
92+
raise ValueError("No environment candidates available for sampling.")
93+
self.env_candidates = env_candidates
9194

9295
if self.agent_candidates is None:
93-
self.agent_candidates = AgentProfile.all()
96+
agent_candidates = AgentProfile.all()
97+
if not agent_candidates:
98+
raise ValueError("No agent candidates available for sampling.")
99+
self.agent_candidates = agent_candidates
94100

95101
agent_candidate_ids: set[str] | None = None
96102
if self.agent_candidates:

sotopia/samplers/uniform_sampler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ def sample(
4747
assert replacement, "Uniform sampling without replacement is not supported yet"
4848

4949
if self.env_candidates is None:
50-
self.env_candidates = EnvironmentProfile.all()
50+
env_candidates = EnvironmentProfile.all()
51+
if not env_candidates:
52+
raise ValueError("No environment candidates available for sampling.")
53+
self.env_candidates = env_candidates
5154

5255
if self.agent_candidates is None:
53-
self.agent_candidates = AgentProfile.all()
56+
agent_candidates = AgentProfile.all()
57+
if not agent_candidates:
58+
raise ValueError("No agent candidates available for sampling.")
59+
self.agent_candidates = agent_candidates
5460

5561
for _ in range(size):
5662
env_profile = random.choice(self.env_candidates)

0 commit comments

Comments
 (0)