Skip to content

Commit

Permalink
Merge branch 'release/1.2.29'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Feb 2, 2022
2 parents 19ab2d5 + 2f33d0c commit ea9f8c2
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 43 deletions.
4 changes: 1 addition & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Checks: "*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm-*,-llvmlibc-*"
Checks: "*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm-*,-llvmlibc-*,-altera-struct-pack-align*"
WarningsAsErrors: "*"
HeaderFilterRegex: ""
FormatStyle: none
CheckOptions:
- key: altera-struct-pack-align.No
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. mac/linux/windows]
- Version [e.g. 1.2.28]
- Version [e.g. 1.2.29]

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
project(Griddly VERSION 1.2.28)
project(Griddly VERSION 1.2.29)

set(BINARY ${CMAKE_PROJECT_NAME})

Expand Down
2 changes: 1 addition & 1 deletion bindings/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace griddly {

PYBIND11_MODULE(python_griddly, m) {
m.doc() = "Griddly python bindings";
m.attr("version") = "1.2.28";
m.attr("version") = "1.2.29";

#ifndef NDEBUG
spdlog::set_level(spdlog::level::debug);
Expand Down
53 changes: 22 additions & 31 deletions bindings/wrapper/EntityObserverWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace griddly {

struct EntityObservations {
std::map<std::string, std::vector<std::vector<float>>> entityObservation{};
std::map<size_t, uint32_t> entityIdMap{};
std::vector<size_t> entityIds{};
std::unordered_map<std::string, std::vector<std::vector<float>>> entityObservation{};
std::unordered_map<size_t, std::array<uint32_t, 2>> entityLocations{};
std::unordered_map<std::string, std::vector<size_t>> entityIds{};
};

class Py_EntityObserverWrapper {
Expand All @@ -36,23 +36,23 @@ class Py_EntityObserverWrapper {
py::dict observation;

auto entityObservationsAndIds = buildEntityObservations(playerId);
auto actionsAndMasks = buildEntityMasks(playerId, entityObservationsAndIds.entityIdMap);
auto actionsAndMasks = buildEntityMasks(playerId);

observation["Entities"] = entityObservationsAndIds.entityObservation;
observation["EntityIds"] = entityObservationsAndIds.entityIds;
observation["EntityIdMap"] = entityObservationsAndIds.entityIdMap;
observation["EntityLocations"] = entityObservationsAndIds.entityLocations;
observation["EntityMasks"] = actionsAndMasks;

return observation;
}

private:
// Build entity masks (for transformer architectures)
py::dict buildEntityMasks(int playerId, std::map<size_t, uint32_t> entityIdMap) const {
std::map<std::string, std::vector<std::vector<uint32_t>>> entityMasks;
std::map<std::string, std::vector<uint32_t>> actorIdx;
py::dict buildEntityMasks(int playerId) const {
std::map<std::string, std::vector<std::vector<uint32_t>>> actorEntityMasks{};
std::map<std::string, std::vector<size_t>> actorEntityIds{};

std::unordered_set<std::string> allAvailableActionNames;
std::unordered_set<std::string> allAvailableActionNames{};

py::dict entitiesAndMasks;

Expand All @@ -79,17 +79,17 @@ class Py_EntityObserverWrapper {
mask[id] = 1;
}

entityMasks[actionName].push_back(mask);
actorIdx[actionName].push_back(entityIdMap.at(entityId));
actorEntityMasks[actionName].push_back(mask);
actorEntityIds[actionName].push_back(entityId);

allAvailableActionNames.insert(actionName);
}
}

for (auto actionName : allAvailableActionNames) {
py::dict entitiesAndMasksForAction;
entitiesAndMasksForAction["ActorIdx"] = actorIdx[actionName];
entitiesAndMasksForAction["Masks"] = entityMasks[actionName];
entitiesAndMasksForAction["ActorEntityIds"] = actorEntityIds[actionName];
entitiesAndMasksForAction["Masks"] = actorEntityMasks[actionName];

entitiesAndMasks[actionName.c_str()] = entitiesAndMasksForAction;
}
Expand All @@ -101,10 +101,9 @@ class Py_EntityObserverWrapper {
EntityObservations buildEntityObservations(int playerId) const {
EntityObservations entityObservationsAndIds;

std::map<std::string, std::vector<std::shared_ptr<Object>>> entityObjects;
std::map<std::string, std::vector<std::vector<float>>> entityObservations;
std::map<size_t, uint32_t> entityIdMap;
std::vector<size_t> entityIds;
std::unordered_map < std::string, std::vector<size_t>> entityIds{};
std::unordered_map<size_t, std::array<uint32_t, 2>> entityLocations{};
std::unordered_map<std::string, std::vector<std::vector<float>>> entityObservations{};

auto grid = gameProcess_->getGrid();

Expand Down Expand Up @@ -132,23 +131,15 @@ class Py_EntityObserverWrapper {
}

entityObservations[name].push_back(featureVector);
entityObjects[name].push_back(object);
}

// All entities are in the map and now we need to calculate the entity ids in the same order
for (auto objects : entityObjects) {
for (auto object : objects.second) {
auto hash = std::hash<std::shared_ptr<Object>>()(object);
entityIdMap.insert({hash, entityIds.size()});
entityIds.push_back(hash);
}
auto hash = std::hash<std::shared_ptr<Object>>()(object);
entityIds[name].push_back(hash);
entityLocations[hash] = {static_cast<uint32_t>(location.x), static_cast<uint32_t>(location.y)};
}

return {
entityObservations,
entityIdMap,
entityIds
};
entityObservations,
entityLocations,
entityIds};
}

std::unordered_map<std::string, std::vector<std::string>> entityVariableMapping_;
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Chris Bamford'

# The full version, including alpha/beta/rc tags
release = '1.2.28'
release = '1.2.29'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def griddly_package_data(config='Debug'):

setup(
name='griddly',
version="1.2.28",
version="1.2.29",
author_email="[email protected]",
description="Griddly Python Libraries",
long_description=long_description,
Expand Down
8 changes: 4 additions & 4 deletions python/tests/entity_observer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ def test_entity_observations(test_name):
entity_masks = entity_observation["EntityMasks"]

entity_mask_one = entity_masks['move_one']
actors_one = entity_mask_one['ActorIdx']
actors_one = entity_mask_one['ActorEntityIds']
mask_one = entity_mask_one["Masks"]

assert actors_one == [0]
assert actors_one == [entity_ids['entity_1'][0]]
assert mask_one == [[1, 1, 1, 1, 0]]

entity_mask_two = entity_masks['move_two']
actors_two = entity_mask_two['ActorIdx']
actors_two = entity_mask_two['ActorEntityIds']
mask_two = entity_mask_two["Masks"]

assert actors_two == [0]
assert actors_two == [entity_ids['entity_1'][0]]
assert mask_two == [[1, 1, 1, 1]]

0 comments on commit ea9f8c2

Please sign in to comment.