How to Use Craftax: Your Guide to Getting Started

Category :

Welcome to the world of Craftax, an innovative Reinforcement Learning (RL) environment that takes cues from roguelike games to enhance your gaming and research experience. In this guide, we will walk you through the basics of using Craftax, from installation to running experiments. Let’s dive in!

Getting Started with Craftax

Installation

To install Craftax, follow these simple steps:

  • To get the latest release:
  • pip install craftax
  • For the most recent commits from the repository:
  • pip install git+https://github.com/MichaelTMatthews/Craftax.git@main

Basic Usage

Once installed, you can start using Craftax as follows:

import jax
from craftax import make_craftax_env_from_name

# Initialize a random number generator
rng = jax.random.PRNGKey(0)
rng, _rng = jax.random.split(rng)
rngs = jax.random.split(_rng, 3)

# Create the environment
env = make_craftax_env_from_name("Craftax-Symbolic-v1", auto_reset=True)
env_params = env.default_params

# Get an initial state and observation
obs, state = env.reset(rngs[0], env_params)

# Pick random action
action = env.action_space(env_params).sample(rngs[1])

# Step environment
obs, state, reward, done, info = env.step(rngs[2], state, action, env_params)

Imagine you’re an explorer in a vast open-world game. Setting off requires preparing your tools (installation), selecting a path (creating the environment), and taking your first steps (executing initial commands). Each command in the code above helps you take one step after another towards navigating the game world.

Running Craftax

To actually play Craftax, run the following command in your terminal:

play_craftax

For the classic version, use:

play_craftax_classic

Be patient! The first rendering may take around 30 seconds, and the first action another 20 seconds, as it compiles in JAX.

Troubleshooting Tips

If you run into issues while using Craftax, consider the following troubleshooting ideas:

  • Optimistic Resets: Ensure that you wrap environments in either OptimisticResetVecEnvWrapper or AutoResetEnvWrapper to avoid invalid states.
  • Texture Caching: If you see errors after editing the game (like adding new blocks), you might be dealing with a stale cache. You can clear it by setting the following environment variable:
  • export CRAFTAX_RELOAD_TEXTURES=true
  • GPU Installation: If you wish to utilize GPU capabilities, remember to install the appropriate JAX wheel for your system.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox

Latest Insights

© 2024 All Rights Reserved

×