Commit ·
a1250db
1
Parent(s): 96daa83
Wire env to per-participant deterministic orders: reset copies the pre-baked order (exact outcomes looked up, not drawn), OrderedEnvStage rebuilds params from PID, render uses 24 box stimuli + 12 houses, rating by box, log stim/house/gid
Browse filesFiles changed (3)
- experiment_structure.py+107-79
- orders.py+19
- smoke_test.py+21-6
31 unmodified lines32333435363750 unmodified lines8889909192939495969722 unmodified lines12012112212312412512612713 unmodified lines1411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771784 unmodified lines18318418518618718818919019119219319419519619719819920020120220320424 unmodified lines22923023123223323423523623750 unmodified lines288289290291292293294295296297298299300301302303304305111 unmodified lines41741841942042142216 unmodified lines43944044144244344444544629 unmodified lines47647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850923 unmodified lines53353453553653753853954054154254354454554654754854955055155255323 unmodified lines577578579580581582583584123 unmodified lines70870971071171271371431 unmodified linesfrom nicegui import app, uiimport spritesimport nicewebrlfrom nicewebrl import JaxWebEnv, TimeStep, TimestepWrapperfrom nicewebrl import Stage, EnvStage, FeedbackStage50 unmodified lines# ----------------------------------------------------------------------------@struct.dataclassclass EnvParams:candidate_pos: jax.Array # (N_CAND, 2)n_trials: jax.Array # scalaractive_mask: jax.Array # (12,) 1 = this house is used this runpractice: jax.Array # scalar 0/1@struct.dataclass22 unmodified lineshouse_active: jax.Array # (12,) boolplace_pairs: jax.Array # (12,2) letterspair_code: jax.Array # (12,) 0..5 (option-pair identity, for data)house_type: jax.Array # (12,) 0..6 (visual house/room theme)side_schedule: jax.Array # (12, N_TRIALS) 0/1def _layout(opt_letters, side_bit):13 unmodified linesjnp.sum(s.consumed)], dtype=jnp.float32)def reset(self, key, params: EnvParams):k_pos, k_pair, k_side = jax.random.split(key, 3)cand = params.candidate_pos# main: shuffle positions + counterbalance pair assignmentpos_perm = jax.random.permutation(k_pos, N_CAND)[:N_PLACES]main_house = cand[pos_perm]pair_perm = jax.random.permutation(k_pair, N_PLACES)main_pairs = jnp.asarray(PLACE_PAIRS_ARR)[pair_perm]main_code = jnp.asarray(BASE_PAIRCODE)[pair_perm]# practice: one fixed nearby house, pair ABprac_house = cand[:N_PLACES].at[0].set(jnp.asarray(PRAC_HOUSE))prac_pairs = jnp.asarray(PLACE_PAIRS_ARR)prac_code = jnp.asarray(BASE_PAIRCODE)pr = params.practicehouse_pos = jnp.where(pr == 1, prac_house, main_house)place_pairs = jnp.where(pr == 1, prac_pairs, main_pairs)pair_code = jnp.where(pr == 1, prac_code, main_code)# visual house type: main = pair_code; practice place 0 = special forest hutprac_type = jnp.asarray(BASE_PAIRCODE).at[0].set(PRAC_HOUSE_TYPE)house_type = jnp.where(pr == 1, prac_type, main_code)side_schedule = jax.random.bernoulli(k_side, 0.5, (N_PLACES, N_TRIALS)).astype(jnp.int32)active = params.active_mask.astype(bool)s = EnvState(mode=jnp.int32(M_OVERWORLD),agent_pos=jnp.asarray(START_POS, jnp.int32),partner_pos=jnp.asarray(PARTNER_START, jnp.int32),facing=jnp.int32(0), walk_frame=jnp.int32(0),consumed=~active, # inactive houses count as donecurrent_place=jnp.int32(-1),trial=jnp.int32(0),n_trials=params.n_trials,4 unmodified lineslast_self_outcome=jnp.int32(0), last_other_outcome=jnp.int32(0),rating_cursor=jnp.int32(RATING_MAX // 2),ratings=jnp.full(N_PLACES, -1, jnp.int32),house_pos=house_pos.astype(jnp.int32),house_active=active,place_pairs=place_pairs.astype(jnp.int32),pair_code=pair_code.astype(jnp.int32),house_type=house_type.astype(jnp.int32),side_schedule=side_schedule,)return self._obs(s), sdef _draw(self, key, good):u = jax.random.uniform(key)p_plus = jnp.where(good == 1, P_PLUS_GOOD, P_PLUS_BAD)p_minus = jnp.where(good == 1, P_MINUS_GOOD, P_MINUS_BAD)return jnp.where(u < p_plus, jnp.int32(1),jnp.where(u < p_plus + p_minus, jnp.int32(-1), jnp.int32(0)))def _overworld(self, key, s, action, params):drow = jnp.where(action == A_UP, -1, jnp.where(action == A_DOWN, 1, 0))dcol = jnp.where(action == A_LEFT, -1, jnp.where(action == A_RIGHT, 1, 0))24 unmodified linesis_choice = (action == A_LEFT) | (action == A_RIGHT)chosen_side = jnp.where(action == A_LEFT, jnp.int32(0), jnp.int32(1))chosen_letter = jnp.where(chosen_side == 0, s.left_letter, s.right_letter)k1, k2 = jax.random.split(key)self_out = self._draw(k1, LETTER_SELF_GOOD[chosen_letter]) * COIN # +100/-100/0other_out = self._draw(k2, LETTER_OTHER_GOOD[chosen_letter]) * COINresolved = s.replace(mode=jnp.int32(M_OUTCOME), chosen_side=chosen_side, chosen_letter=chosen_letter,last_self_outcome=self_out, last_other_outcome=other_out,50 unmodified lineswrapped_env = TimestepWrapper(raw_env, autoreset=True)jax_web_env = JaxWebEnv(env=wrapped_env, actions=action_array)main_params = EnvParams(candidate_pos=jnp.asarray(CANDIDATE_POS, jnp.int32),n_trials=jnp.int32(N_TRIALS),active_mask=jnp.ones(N_PLACES, jnp.int32),practice=jnp.int32(0),)practice_params = EnvParams(candidate_pos=jnp.asarray(CANDIDATE_POS, jnp.int32),n_trials=jnp.int32(PRAC_TRIALS),active_mask=jnp.zeros(N_PLACES, jnp.int32).at[0].set(1),practice=jnp.int32(1),)# ----------------------------------------------------------------------------111 unmodified linestrial, mode = _i(s.trial), _i(s.mode)n_trials = _i(s.n_trials)left_letter, right_letter = _i(s.left_letter), _i(s.right_letter)sc, oc = _i(s.self_coins), _i(s.other_coins)s_out, o_out = _i(s.last_self_outcome), _i(s.last_other_outcome)chosen_side = _i(s.chosen_side)16 unmodified linesfor x, letter, side in ((lx, left_letter, 0), (rx, right_letter, 1)):chosen = (mode == M_OUTCOME) and (chosen_side == side)sprites.draw_chest(d, x, y0, cw, ch, LETTER_COLOR[letter], is_open=chosen, highlight=chosen)sprites.draw_key(d, x + cw // 2 - 12, table_top + 4, LETTER_COLOR[letter])# ---- top-center prompt / verbose feedback ----if mode == M_CHOICE:29 unmodified linescursor = _i(s.rating_cursor)sc, oc = _i(s.self_coins), _i(s.other_coins)opt = np.asarray(s.place_pairs)[place_id]lo, ro = int(opt[0]), int(opt[1])left_col, right_col = LETTER_COLOR[lo], LETTER_COLOR[ro]left_name, right_name = COLOR_NAMES[lo].upper(), COLOR_NAMES[ro].upper()img = Image.new("RGB", (W, H), (40, 44, 60))d = ImageDraw.Draw(img)T(d, W // 2, 56, "You've taken all you can get from this house!", size=22, bold=True,fill=(255, 230, 120), center=True, outline=True)T(d, W // 2, 90, f"Which chest did you prefer - the {left_name} or the {right_name} one?",size=20, bold=True, fill=(255, 255, 255), center=True, outline=True)T(d, W // 2, 118, "(it's the chest's colour that matters, not its side)", size=14,fill=(210, 210, 220), center=True, outline=True)sprites.draw_chest(d, 70, 210, 120, 90, left_col, is_open=False)sprites.draw_chest(d, W - 70 - 120, 210, 120, 90, right_col, is_open=False)n = RATING_MAX + 1x0, x1, y = 240, W - 240, 250for i in range(n):cx = x0 + (x1 - x0) * i // (n - 1)r = 17 if i == cursor else 11fill = (241, 196, 15) if i == cursor else (95, 100, 124)d.ellipse([cx - r, y - r, cx + r, y + r], fill=fill, outline=(20, 24, 32), width=2)T(d, 130, 320, "strongly prefer", size=14, fill=(220, 220, 228), center=True, outline=True)T(d, 130, 338, f"the {left_name} chest", size=16, bold=True, fill=left_col, center=True, outline=True)T(d, W - 130, 320, "strongly prefer", size=14, fill=(220, 220, 228), center=True, outline=True)T(d, W - 130, 338, f"the {right_name} chest", size=16, bold=True, fill=right_col, center=True, outline=True)T(d, W // 2, 320, "no preference", size=14, fill=(220, 220, 228), center=True, outline=True)T(d, W // 2, H - 70, "Move with <- / ->, then press SPACE to confirm", size=18, bold=True,fill=(255, 255, 255), center=True, outline=True)return img23 unmodified linesdef custom_data_fn(timestep):s = timestep.statecp = jnp.clip(s.current_place, 0, N_PLACES - 1)pid = ""# stash latest non-practice totals so the final screen can show points -> moneytry:pid = app.storage.user.get("pid", "")if int(s.practice) == 0:app.storage.user["self_points"] = int(s.self_coins)app.storage.user["partner_points"] = int(s.other_coins)except Exception:passreturn dict(pid=pid,mode=s.mode, place=s.current_place, trial=s.trial, n_trials=s.n_trials,practice=s.practice, pair_code=s.pair_code[cp],left_letter=s.left_letter, right_letter=s.right_letter,chosen_side=s.chosen_side, chosen_letter=s.chosen_letter,self_outcome=s.last_self_outcome, other_outcome=s.last_other_outcome,self_coins=s.self_coins, other_coins=s.other_coins,rating=s.ratings[cp], rating_cursor=s.rating_cursor,23 unmodified linesreturn timestep.last()def make_env_stage(name, params, metadata):return EnvStage(name=name, web_env=jax_web_env, action_keys=action_keys, action_to_name=action_to_name,env_params=params, render_fn=render_state, vmap_render_fn=vmap_render_fn, precompile=False,display_fn=env_stage_display_fn, evaluate_success_fn=never_success, check_finished=all_done,123 unmodified lines# Assemble experiment (intro: welcome/instructions/explorer live in web_app.py)# ----------------------------------------------------------------------------all_stages = [make_env_stage("Practice", practice_params, dict(task="practice")),FeedbackStage(name="Quiz", display_fn=quiz_display, custom_key_press_fn=_ignore_keys),make_env_stage("Explore", main_params, dict(task="main")),]31 unmodified lines3233343536373850 unmodified lines899091929394959697989910010110210310422 unmodified lines12712812913013113213313413513613 unmodified lines1501511521531541551561571581591601611621634 unmodified lines16816917017117217317417517617717817918018118218318424 unmodified lines20921021121221321421521621721821950 unmodified lines270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307111 unmodified lines41942042142242342442516 unmodified lines44244344444544644744844945045129 unmodified lines48148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451523 unmodified lines53954054154254354454554654754854955055155255355455555655755855956056156256323 unmodified lines587588589590591592593594595596597598599600601602603604605606607608609610611612123 unmodified lines73673773873974074174231 unmodified linesfrom nicegui import app, uiimport spritesimport ordersimport nicewebrlfrom nicewebrl import JaxWebEnv, TimeStep, TimestepWrapperfrom nicewebrl import Stage, EnvStage, FeedbackStage50 unmodified lines# ----------------------------------------------------------------------------@struct.dataclassclass EnvParams:house_pos: jax.Array # (12,2)place_pairs: jax.Array # (12,2) letters per place (in block order)pair_code: jax.Array # (12,)house_type: jax.Array # (12,) 0..12stim_map: jax.Array # (4,) letter -> stimulus id (0..23)side_schedule: jax.Array # (12,N_TRIALS)outcomes: jax.Array # (12,2,2,N_TRIALS) [place, option, recipient, trial]n_trials: jax.Arrayactive_mask: jax.Array # (12,)practice: jax.Array@struct.dataclass22 unmodified lineshouse_active: jax.Array # (12,) boolplace_pairs: jax.Array # (12,2) letterspair_code: jax.Array # (12,) 0..5 (option-pair identity, for data)house_type: jax.Array # (12,) 0..12 (which distinct house / room theme)stim_map: jax.Array # (4,) letter -> stimulus idside_schedule: jax.Array # (12, N_TRIALS) 0/1outcomes: jax.Array # (12,2,2,N_TRIALS) pre-baked exact outcomesdef _layout(opt_letters, side_bit):13 unmodified linesjnp.sum(s.consumed)], dtype=jnp.float32)def reset(self, key, params: EnvParams):# the whole order is precomputed (per participant) and just copied into stateactive = params.active_mask.astype(bool)s = EnvState(mode=jnp.int32(M_OVERWORLD),agent_pos=jnp.asarray(START_POS, jnp.int32),partner_pos=jnp.asarray(PARTNER_START, jnp.int32),facing=jnp.int32(0), walk_frame=jnp.int32(0),consumed=~active,current_place=jnp.int32(-1),trial=jnp.int32(0),n_trials=params.n_trials,4 unmodified lineslast_self_outcome=jnp.int32(0), last_other_outcome=jnp.int32(0),rating_cursor=jnp.int32(RATING_MAX // 2),ratings=jnp.full(N_PLACES, -1, jnp.int32),house_pos=params.house_pos.astype(jnp.int32),house_active=active,place_pairs=params.place_pairs.astype(jnp.int32),pair_code=params.pair_code.astype(jnp.int32),house_type=params.house_type.astype(jnp.int32),stim_map=params.stim_map.astype(jnp.int32),side_schedule=params.side_schedule.astype(jnp.int32),outcomes=params.outcomes.astype(jnp.int32),)return self._obs(s), sdef _overworld(self, key, s, action, params):drow = jnp.where(action == A_UP, -1, jnp.where(action == A_DOWN, 1, 0))dcol = jnp.where(action == A_LEFT, -1, jnp.where(action == A_RIGHT, 1, 0))24 unmodified linesis_choice = (action == A_LEFT) | (action == A_RIGHT)chosen_side = jnp.where(action == A_LEFT, jnp.int32(0), jnp.int32(1))chosen_letter = jnp.where(chosen_side == 0, s.left_letter, s.right_letter)# which option of this place's pair (0 or 1), then look up the pre-baked outcomeopt_idx = jnp.where(chosen_letter == s.place_pairs[s.current_place, 0],jnp.int32(0), jnp.int32(1))self_out = s.outcomes[s.current_place, opt_idx, 0, s.trial]other_out = s.outcomes[s.current_place, opt_idx, 1, s.trial]resolved = s.replace(mode=jnp.int32(M_OUTCOME), chosen_side=chosen_side, chosen_letter=chosen_letter,last_self_outcome=self_out, last_other_outcome=other_out,50 unmodified lineswrapped_env = TimestepWrapper(raw_env, autoreset=True)jax_web_env = JaxWebEnv(env=wrapped_env, actions=action_array)def build_env_params(order, n_trials, active_mask, practice):"""Turn an `orders.make_order(...)` dict into EnvParams (jnp arrays)."""return EnvParams(house_pos=jnp.asarray(order["house_pos"], jnp.int32),place_pairs=jnp.asarray(order["place_pairs"], jnp.int32),pair_code=jnp.asarray(order["pair_code"], jnp.int32),house_type=jnp.asarray(order["house_type"], jnp.int32),stim_map=jnp.asarray(order["stim_map"], jnp.int32),side_schedule=jnp.asarray(order["side_schedule"], jnp.int32),outcomes=jnp.asarray(order["outcomes"], jnp.int32),n_trials=jnp.int32(n_trials),active_mask=jnp.asarray(active_mask, jnp.int32),practice=jnp.int32(practice),)_MAIN_ACTIVE = np.ones(N_PLACES, np.int32)_PRAC_ACTIVE = np.zeros(N_PLACES, np.int32); _PRAC_ACTIVE[0] = 1def main_params_for(pid):return build_env_params(orders.make_order(pid), N_TRIALS, _MAIN_ACTIVE, 0)def practice_params():return build_env_params(orders.make_practice_order(), PRAC_TRIALS, _PRAC_ACTIVE, 1)# default params for module-load compilation (overridden per participant at runtime)main_params = main_params_for("0001")practice_params_default = practice_params()# ----------------------------------------------------------------------------111 unmodified linestrial, mode = _i(s.trial), _i(s.mode)n_trials = _i(s.n_trials)left_letter, right_letter = _i(s.left_letter), _i(s.right_letter)stim_map = np.asarray(s.stim_map)sc, oc = _i(s.self_coins), _i(s.other_coins)s_out, o_out = _i(s.last_self_outcome), _i(s.last_other_outcome)chosen_side = _i(s.chosen_side)16 unmodified linesfor x, letter, side in ((lx, left_letter, 0), (rx, right_letter, 1)):chosen = (mode == M_OUTCOME) and (chosen_side == side)stim = int(stim_map[letter])sprites.draw_stim_chest(d, x, y0, cw, ch, stim, is_open=chosen, highlight=chosen)sprites.draw_key(d, x + cw // 2 - 12, table_top + 4,sprites.STIM_COLORS[stim % len(sprites.STIM_COLORS)])# ---- top-center prompt / verbose feedback ----if mode == M_CHOICE:29 unmodified linescursor = _i(s.rating_cursor)sc, oc = _i(s.self_coins), _i(s.other_coins)opt = np.asarray(s.place_pairs)[place_id]stim_map = np.asarray(s.stim_map)stim_l, stim_r = int(stim_map[int(opt[0])]), int(stim_map[int(opt[1])])img = Image.new("RGB", (W, H), (40, 44, 60))d = ImageDraw.Draw(img)T(d, W // 2, 56, "You've taken all you can get from this house!", size=22, bold=True,fill=(255, 230, 120), center=True, outline=True)T(d, W // 2, 90, "Which box did you prefer?", size=20, bold=True,fill=(255, 255, 255), center=True, outline=True)T(d, W // 2, 118, "(it's the box itself that matters, not which side it was on)", size=14,fill=(210, 210, 220), center=True, outline=True)sprites.draw_stim_chest(d, 70, 200, 120, 96, stim_l, is_open=False)sprites.draw_stim_chest(d, W - 70 - 120, 200, 120, 96, stim_r, is_open=False)n = RATING_MAX + 1x0, x1, y = 250, W - 250, 250for i in range(n):cx = x0 + (x1 - x0) * i // (n - 1)r = 17 if i == cursor else 11fill = (241, 196, 15) if i == cursor else (95, 100, 124)d.ellipse([cx - r, y - r, cx + r, y + r], fill=fill, outline=(20, 24, 32), width=2)T(d, 130, 322, "strongly prefer", size=14, fill=(220, 220, 228), center=True, outline=True)T(d, 130, 340, "this box", size=16, bold=True,fill=sprites.STIM_COLORS[stim_l % len(sprites.STIM_COLORS)], center=True, outline=True)T(d, W - 130, 322, "strongly prefer", size=14, fill=(220, 220, 228), center=True, outline=True)T(d, W - 130, 340, "this box", size=16, bold=True,fill=sprites.STIM_COLORS[stim_r % len(sprites.STIM_COLORS)], center=True, outline=True)T(d, W // 2, 322, "no preference", size=14, fill=(220, 220, 228), center=True, outline=True)T(d, W // 2, H - 70, "Move with <- / ->, then press SPACE to confirm", size=18, bold=True,fill=(255, 255, 255), center=True, outline=True)return img23 unmodified linesdef custom_data_fn(timestep):s = timestep.statecp = jnp.clip(s.current_place, 0, N_PLACES - 1)cl = jnp.clip(s.chosen_letter, 0, 3)pid, gid = "", -1# stash latest non-practice totals so the final screen can show points -> moneytry:pid = app.storage.user.get("pid", "")gid = orders.parse_pid(pid)[0]if int(s.practice) == 0:app.storage.user["self_points"] = int(s.self_coins)app.storage.user["partner_points"] = int(s.other_coins)except Exception:passreturn dict(pid=pid, gid=gid,mode=s.mode, place=s.current_place, trial=s.trial, n_trials=s.n_trials,practice=s.practice, pair_code=s.pair_code[cp], house_type=s.house_type[cp],left_letter=s.left_letter, right_letter=s.right_letter,left_stim=s.stim_map[s.left_letter], right_stim=s.stim_map[s.right_letter],chosen_side=s.chosen_side, chosen_letter=s.chosen_letter,chosen_stim=s.stim_map[cl],self_outcome=s.last_self_outcome, other_outcome=s.last_other_outcome,self_coins=s.self_coins, other_coins=s.other_coins,rating=s.ratings[cp], rating_cursor=s.rating_cursor,23 unmodified linesreturn timestep.last()class OrderedEnvStage(EnvStage):"""Rebuilds env_params for THIS participant (from their PID) just before the reset.Safe under concurrency: env_params is only used by reset(), which runs synchronouslyat the very start of activate() with no await in between; step() ignores params."""async def activate(self, container):task = self.metadata.get("task", "main")try:if task == "practice":self.env_params = practice_params()else:self.env_params = main_params_for(app.storage.user.get("pid", "0001"))except Exception as e:logger.warning(f"order build failed, using default: {e}")await super().activate(container)def make_env_stage(name, params, metadata):return OrderedEnvStage(name=name, web_env=jax_web_env, action_keys=action_keys, action_to_name=action_to_name,env_params=params, render_fn=render_state, vmap_render_fn=vmap_render_fn, precompile=False,display_fn=env_stage_display_fn, evaluate_success_fn=never_success, check_finished=all_done,123 unmodified lines# Assemble experiment (intro: welcome/instructions/explorer live in web_app.py)# ----------------------------------------------------------------------------all_stages = [make_env_stage("Practice", practice_params_default, dict(task="practice")),FeedbackStage(name="Quiz", display_fn=quiz_display, custom_key_press_fn=_ignore_keys),make_env_stage("Explore", main_params, dict(task="main")),]
107 unmodified lines108109110111112113107 unmodified lines)def manifest_row(pid):"""One flat dict summarising a participant's randomisation (for the rando log)."""o = make_order(pid)107 unmodified lines108109110111112113114115116117118119120121122123124125126127128129130131132107 unmodified lines)def make_practice_order():"""A fixed practice order: one nearby 'forest hut', the AB pair, clear outcomes."""o = make_order("90000")o["house_pos"] = o["house_pos"].copy()o["house_pos"][0] = [12, 16] # near the start tileo["place_pairs"] = o["place_pairs"].copy()o["place_pairs"][0] = [0, 1] # pair AB (A=good/good, B=good/bad)o["pair_code"] = o["pair_code"].copy()o["pair_code"][0] = 0o["house_type"] = o["house_type"].copy()o["house_type"][0] = 12 # practice-only forest huto["outcomes"] = o["outcomes"].copy()rng = np.random.default_rng(123)for opt, letter in enumerate([0, 1]): # rebuild place-0 outcomes for ABo["outcomes"][0, opt, 0] = _exact_sequence(LETTER_SELF_GOOD[letter], rng)o["outcomes"][0, opt, 1] = _exact_sequence(LETTER_OTHER_GOOD[letter], rng)return odef manifest_row(pid):"""One flat dict summarising a participant's randomisation (for the rando log)."""o = make_order(pid)
71 unmodified lines7273747576777879808182838471 unmodified linesassert len(set(used)) == len(used), "house positions must be distinct"# per-session randomization: positions differ across seedsdef positions(seed):ts = E.jax_web_env.reset(jax.random.PRNGKey(seed), E.main_params)return [tuple(int(v) for v in np.asarray(ts.state.house_pos)[i]) for i in range(E.N_PLACES)]run(E.main_params, "MAIN")run(E.practice_params, "PRACTICE")assert positions(1) != positions(2), "house layout should differ across sessions"print("\nALL SMOKE TESTS PASSED")71 unmodified lines7273747576777879808182838485868788899091929394959697989971 unmodified linesassert len(set(used)) == len(used), "house positions must be distinct"# deterministic per-PID orders: different IDs -> different orders, same ID -> identicaldef order_sig(pid):p = E.main_params_for(pid)return (tuple(np.asarray(p.house_pos).ravel().tolist()),tuple(np.asarray(p.stim_map).tolist()),tuple(np.asarray(p.house_type).tolist()))run(E.main_params, "MAIN")run(E.practice_params_default, "PRACTICE")assert order_sig("0001") != order_sig("0002"), "different IDs should give different orders"assert order_sig("0042") == order_sig("0042"), "same ID must be reproducible"# exact outcome counts (15 plus / 3 minus / 2 zero per place/option/recipient)om = np.asarray(E.main_params_for("0007").outcomes)for p in range(E.N_PLACES):for opt in range(2):for r in range(2):seq = om[p, opt, r]assert (seq == 100).sum() + (seq == -100).sum() == 18 and (seq == 0).sum() == 2# the houses a participant visits should all be distinct (12 different houses)p7 = E.main_params_for("0007")assert len(set(np.asarray(p7.house_type).tolist())) == E.N_PLACES, "12 houses must be distinct"print("\nALL SMOKE TESTS PASSED")
experiment_structure.py+107-79
orders.py+19
smoke_test.py+21-6