File size: 3,079 Bytes
aab0192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Test the hypothesis-lab environment running locally on Docker (port 8000).
Uses the standard OpenEnv interface: env.reset() and env.step(action).
"""
import asyncio
import sys
sys.path.insert(0, "/Users/sbhimraj/Documents/Openenv/lab-experiment")

from client import HypothesisLabEnv
from models import HypLabAction, ActionType, ExperimentType


async def main():
    print("=== Testing local hypothesis-lab environment ===\n")

    async with HypothesisLabEnv(base_url="http://localhost:8000") as env:

        # Reset episode
        result = await env.reset(noise_level="low")
        obs = result.observation
        variables = obs.available_variables
        print(f"[reset]")
        print(f"  variables:  {variables}")
        print(f"  budget:     {obs.budget_remaining}")
        print(f"  message:    {obs.system_message[:120]}\n")

        v1, v2 = variables[0], variables[1]

        # Step 1 — intervention experiment
        action = HypLabAction(
            action_type=ActionType.EXPERIMENT,
            experiment_type=ExperimentType.INTERVENTION,
            control_variable=v1,
            control_value=2.5,
            target_variable=v2,
        )
        result = await env.step(action)
        obs = result.observation
        print(f"[step 1: intervention]")
        print(f"  {v1}=2.5 → {v2} = {obs.result_value}")
        print(f"  info_gain:   {obs.info_gain_reward}")
        print(f"  budget left: {obs.budget_remaining}")
        print(f"  done:        {result.done}\n")

        # Step 2 — correlation experiment
        action = HypLabAction(
            action_type=ActionType.EXPERIMENT,
            experiment_type=ExperimentType.CORRELATION,
            control_variable=v1,
            control_range=[0.0, 1.0, 2.0, 3.0, 4.0],
            target_variable=v2,
        )
        result = await env.step(action)
        obs = result.observation
        print(f"[step 2: correlation]")
        print(f"  {v1} swept → {v2} = {obs.result_value}")
        print(f"  info_gain:   {obs.info_gain_reward}")
        print(f"  budget left: {obs.budget_remaining}")
        print(f"  done:        {result.done}\n")

        # Step 3 — submit hypothesis
        action = HypLabAction(
            action_type=ActionType.SUBMIT,
            hypothesis_text=f"{v2} increases linearly with {v1} by approximately 2.5 units",
            confidence=0.7,
        )
        result = await env.step(action)
        obs = result.observation
        print(f"[step 3: submit]")
        print(f"  reward:              {result.reward}")
        print(f"  accuracy_score:      {obs.accuracy_score}")
        print(f"  precision_bonus:     {obs.precision_bonus}")
        print(f"  calibration_score:   {obs.calibration_score}")
        print(f"  efficiency_bonus:    {obs.efficiency_bonus}")
        print(f"  done:                {result.done}")
        if obs.ground_truth_revealed:
            print(f"  ground_truth:        {obs.ground_truth_revealed[:300]}")

    print("\n=== Done — environment is working correctly ===")


asyncio.run(main())