Source code for schola.core.spaces.binary

Copied!


# Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights Reserved.

"""
Implementation of a MultiBinarySpace, a space representing a vector of binary values.
"""
from collections import OrderedDict
from functools import cached_property
from typing import Dict, List, Union
import gymnasium
import schola.generated.Spaces_pb2 as proto_spaces
import schola.generated.Points_pb2 as proto_points
import numpy as np
import logging
from .base import UnrealSpace


[docs] class MultiBinarySpace(gymnasium.spaces.MultiBinary, UnrealSpace): """ A Space representing a vector of binary values. Parameters ---------- n : int The number of binary values in the space. Attributes ---------- shape : Tuple[int] The shape of the space. n : int The number of binary values in the space. See Also -------- gymnasium.spaces.MultiBinary : The gym space object that this class is analogous to. proto_spaces.BinarySpace : The protobuf representation of this space. """ proto_space = proto_spaces.BinarySpace _name = "binary_space"
[docs] def __init__(self, n : int): super().__init__(n=n)
[docs] def to_normalized(self): """ Cannot normalize a binary space, so return self. """ return self
[docs] @classmethod def from_proto(cls, message : proto_spaces.BinarySpace): return MultiBinarySpace(message.shape)
[docs] @classmethod def is_empty_definition(cls, message: proto_spaces.BinarySpace): return message.shape == 0
[docs] def fill_proto(self, msg : proto_points.FundamentalPoint, values): msg.binary_point.values.extend(values)
[docs] @classmethod def merge(cls, *spaces : List["MultiBinarySpace"]) -> "MultiBinarySpace": """ Merge multiple MultiBinarySpaces into a single space. Parameters ---------- *spaces : List[MultiBinarySpace] The spaces to merge. Returns ------- MultiBinarySpace The merged space. Raises ------ TypeError If any of the spaces are not MultiBinarySpaces. Examples -------- >>> merged_space = MultiBinarySpace.merge(MultiBinarySpace(3), MultiBinarySpace(4)) >>> merged_space.n 7 """ try: return MultiBinarySpace(sum((space.n for space in spaces))) except: raise TypeError("can only merge MultiBinarySpaces with other MultiBinarySpaces")
[docs] def process_data(self, msg: proto_points.FundamentalPoint) -> np.ndarray: return np.asarray(msg.binary_point.values)
def __len__(self) -> int: return self.shape[0]

Related pages

  • Visit the Schola product page for download links and more information.

Looking for more documentation on GPUOpen?

AMD GPUOpen software blogs

Our handy software release blogs will help you make good use of our tools, SDKs, and effects, as well as sharing the latest features with new releases.

GPUOpen Manuals

Don’t miss our manual documentation! And if slide decks are what you’re after, you’ll find 100+ of our finest presentations here.

AMD GPUOpen Performance Guides

The home of great performance and optimization advice for AMD RDNA™ 2 GPUs, AMD Ryzen™ CPUs, and so much more.

Getting started: AMD GPUOpen software

New or fairly new to AMD’s tools, libraries, and effects? This is the best place to get started on GPUOpen!

AMD GPUOpen Getting Started Development and Performance

Looking for tips on getting started with developing and/or optimizing your game, whether on AMD hardware or generally? We’ve got you covered!

AMD GPUOpen Technical blogs

Browse our technical blogs, and find valuable advice on developing with AMD hardware, ray tracing, Vulkan®, DirectX®, Unreal Engine, and lots more.

Find out more about our software!

AMD GPUOpen Effects - AMD FidelityFX technologies

Create wonder. No black boxes. Meet the AMD FidelityFX SDK!

AMD GPUOpen Samples

Browse all our useful samples. Perfect for when you’re needing to get started, want to integrate one of our libraries, and much more.

AMD GPUOpen developer SDKs

Discover what our SDK technologies can offer you. Query hardware or software, manage memory, create rendering applications or machine learning, and much more!

AMD GPUOpen Developer Tools

Analyze, Optimize, Profile, Benchmark. We provide you with the developer tools you need to make sure your game is the best it can be!