# Compute actions Programmatically

**URL:** <https://discuss.ray.io/t/compute-actions-programmatically/4899>\
**Category:** RLlib\
**Created:** [February 2, 2022, 8:18pm UTC](https://discuss.ray.io/t/compute-actions-programmatically/4899 "2022-02-02T20:18:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fdmartins](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@fdmartins](https://discuss.ray.io/u/fdmartins)\
**Post date:** [February 2, 2022, 8:18pm UTC](https://discuss.ray.io/t/compute-actions-programmatically/4899/1 "2022-02-02T20:18:05Z")

</div>

Hello Ray Team!

I’m trying to run the trained model in the “traditional method” environment. I’m using a custom version of the LunarLander environment, with multiple and continuous actions (spaces.Box) .

But action returned by compute\_single\_action function has only one dimension.

what is the better way to compute the action of an observation/state?

Thank you!!

```auto
trainer = agents.ppo.PPOTrainer(.....)

trainer.evaluate() # <== works fine after train!

...

env = MyLunarLander()

while True:
    episode_reward = 0
    done = False
    obs = env.reset()
    while not done:
        
        action = trainer.compute_single_action(obs) # return only one integer. 
        obs, reward, done, info = env.step(action) # exception! IndexError: invalid index to scalar variable.
        episode_reward += reward
        env.render()

    print("Total Reward:", episode_reward)

```

---

<div class="post-metadata">

**Author:** ![Lars\_Simon\_Zehnder](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/lars_simon_zehnder/32/1185_2.png) [@Lars\_Simon\_Zehnder](https://discuss.ray.io/u/Lars_Simon_Zehnder)\
**Post date:** [February 5, 2022, 6:40pm UTC](https://discuss.ray.io/t/compute-actions-programmatically/4899/2 "2022-02-05T18:40:46Z")

</div>

Hi @fdmartins ,

and welcome to the discussion board. The error you are encountering cannot be reproduced because some code is missing. Especially, there is no way to understand what your `MyLunarLander` environment is doing internally. You need to provide more code, if you want to have answers that help you at your problem.
