Giter VIP home page Giter VIP logo

minds_crawl's Introduction

Mind's Crawl

Codacy Badge Ubuntu build

This is a simulation of Physarum Polycephalum, written in CUDA, but can be compiled for CPU execution with NVCC.

Compiling

Before compiling the project, clone the repository with the submodules:

git clone https://github.com/physarumAdv/minds_crawl.git --recursive
cd minds_crawl

To compile (the produced executable will require an NVidia GPU to run):

mkdir cmake-build-release && cd cmake-build-release
cmake ..
cmake --build . -- -j`nproc`

Note that there is also a way to produce an executable which will only use CPU for running, however it's highly unrecommended to use this mode for any purposes but debugging:

mkdir cmake-build-debug && cd cmake-build-debug
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCOMPILE_FOR_CPU=ON
cmake --build . -- -j`nproc`

Executing

To run the application, you have to:

  1. Start a visualization app (we recommend this one)

  2. Create a directory config in the process's working directory with a file visualization_endpoint.txt inside it, containing 2 urls which accepts the simulated data (the first url for particles and the second for polyhedron. An example is in config/visualization_endpoint_example.txt)

Authors

Nikolay Nechaev, [email protected]

Tatiana Kadykova, [email protected]

Paul Artushkov, [email protected]

Olga Starunova, [email protected]

minds_crawl's People

Contributors

codacy-badger avatar kolayne avatar pavtiger avatar tanya-kta avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

minds_crawl's Issues

Too much trail is added when nutrients are projected

It is not guaranteed, that all the nodes in the following loops are unique: it is possible that node A has node B as its neighbour by more than one direction (for example, (A->get_top() == &B) && (A->get_right() == &B)). In such situation B->temp_trail will be increased twice instead of once.

We need to fix this piece of code, and also look for similar cases and either fix them if they are affected by the same mistake or write a comment explaining why this is not an issue there, to make it clear that the piece of code was not forgotten but is correct.

MapNode *left = self->get_left();
for(MapNode *node : {left->get_top(), left,
left->get_bottom()}) // for each leading node of rows of 3x3 square
{
for(int i = 0; i < 3; ++i)
{
atomicAdd(&node->trail, trail_value); // add trail
node = node->get_right(); // move to next node in row
}
}

Optimize `SimulationMap` constructor complexity

Current SimulationMap constructor complexity seems to be N^2, where N is the number of nodes being created (because of find_index_of_nearest_node's complexity N). Must be better. Should be fixable with a hash map

`MapNode` constructor: accept face index instead of a `Face`

__host__ __device__ MapNode::MapNode(Polyhedron *polyhedron, Face *polyhedron_face, SpacePoint coordinates) :
trail(0), temp_trail(0), left(nullptr), top(nullptr), right(nullptr), bottom(nullptr), polyhedron(polyhedron),
polyhedron_face(polyhedron_face), coordinates(coordinates), contains_food(false), particle(nullptr)

Now constructor accepts Face *polyhedron_face, so this face can be not connected with accepted polyhedron
Refactor this to accepting int polyhedron_face_id

Optimize particles' motor behavior by predicting impossibility of crossing edges

Because the distance between two (neighbor) MapNodes is approximately 2 * jones_constants::speed, when a particle makes a move it's guaranteed that if all the neighbor nodes of the "current" node (on which the particle is located) have the same face with the current node, then after the move the particle will stay on the same face, so there is no need to project the move vector. However, it is not checked and we always do project the vector, which is suboptimal:

SpacePoint end = get_projected_vector_end(coordinates, coordinates + direction_vector,
map_node->get_face(), map_node->get_polyhedron());

Bus error (SIGBUS)

When running in the debug mode with compilation for GPU, SIGBUS is raised in main.cu inside main while trying to get access to simulation_map->nodes

Illegal memory access inside of `SimulationMap` constructor

(This may be a duplicate of #29 or a symptom of #32. This is likely to be a duplicate of #31)

For smaller cubes, which seems to be not affected by #32 (at least, I'm not receiving SIGABRTs for them), another error occurs.

The app compiled for GPU fails to finish constructing a SimulationMap object because of an illegal memory access (attaching a patch I'm using to determine this)
gpu.patch.txt (GitHub doesn't allow uploading .patch files for some reason...)

The app compiled for CPU does finish SimulationMap initialization (at least for me) but fails on the second iteration of the loop:

while(true)
{
for(RunIterationFunc f : iteration_runners)
{
f(simulation_map, &iteration_number);
}
if(!send_particles_to_visualization(visualization_endpoint, simulation_map->nodes,
simulation_map->get_n_of_nodes()))
{
std::cerr << "Error sending http request to visualization. Stopping the simulation process\n";
break;
}
}

Though I'm not 100% sure it's the same issue as the problem described above...

Rearrange code at fucking_shit.*

The fucking_shit.cu and fucking_shit.cuh files were created in order to save time on deciding where to place some functions and which scope they should be located at. I think it's time to fix this. The functions located at fucking_shit.cu/cuh should either be moved to other files, become methods or be removed at all

Refactor `nodes_direction`

auto *nodes_directions = (SpacePoint *)malloc(sizeof(SpacePoint) * max_number_of_nodes);

Now each node has its own direction to the top neighbor, but this direction is the same for all nodes of the same face (nodes on different faces have different directions)
Change nodes_directions to an array of size n_of_faces. When the first node is created on the face, direction to all top neighbors of all nodes lying on this face must be assigned in this array

Stack smashing (SIGABRT)

When running in the debug mode with compilation for CPU, SIGABRT is raised inside of the SimulationMap constructor. According to git bisect, the problem first appeared at d5411a5

Using `particle` field in move/copy constructors of `MapNode`

Because it's not possible to allocate an array of MapNodes with the operator new[] when using an array of MapNodes user will face a problem: when trying to replace an element of the array with another MapNode object, the destructor will be called for the old object, which was never constructed (but instead was allocated with malloc or created in any other c-style way) and, therefore, has the particle field invalidated. When the destructor is called, it tries to delete a particle by the particle address, which is invalid. This results in an error.

The workaround is to call the detach_particle() method before replacing an array object, but it looks ugly and should be fixed on the MapNode class side

nodes[n_of_nodes].detach_particle();

Also, the call to detach_particle() in the above piece of code must be commented. It looks absolutely out of place without a comment

Automatically set vertices in format described in docstring of `Face::Face`

First vertex of Face::vertices must be repeated in the end, but it's better if the user doesn't have to do that. Face constructor should get vertices and their number without repetition, then allocate memory for Face::vertices of size n_of_vertices + 1. Face::n_of_vertices should be equal n_of_vertices

Remove the `Particle::normal` field

The normal field is currently a normal of the face the particle is located at. But this is a duplicated information (the normal is stored in the Face object already), neither normal is a property of a particle in any way. So, the field must be removed, the some_particle->map_node->get_face()->get_normal() expression should be used to retrieve a normal given a particle

/// Normal to the current face
SpacePoint normal;

Refactor documentation and identifiers' names

Reread the whole code and bring both identifiers' names and documentation to a single style. Also, fix typos, language mistakes. It would be perfect to create a Markdown document describing the rules of our documenting style

Refactor includes of files and libraries

Check all includes and rewrite them to follow the rule: all files and libraries used in file A has to be included in file A, even if some of them are already included through other files. Also check for other problems such as unused includes. For example:

Incorrect:

//a.cpp
#include <cmath>

//using `cmath` functions
//b.cpp
#include "a.cpp"

//using `cmath` and `a.cpp` functions

Correct:

//a.cpp
#include <cmath>

//using `cmath` functions
//b.cpp
#include <cmath>

#include "a.cpp"

//using `cmath` and `a.cpp` functions

`Particle::do_motor_behaviours` doesn't recognize all the cases of the face change possibility

Not only the map_node neighbours but also their neighbours should be checked in this piece of code:

MapNode *node_neighbors[] = {map_node->get_left(), map_node->get_top(), map_node->get_right(),
map_node->get_bottom()};
for(MapNode *neighbor : node_neighbors)
{
if(neighbor->get_face() != map_node->get_face()) // If any of the neighbor nodes is on a different face
{
// Then particle might move to a different face, so project coordinates to the polyhedron's surface
end = get_projected_vector_end(coordinates, end, map_node->get_face(), map_node->get_polyhedron());
break;
}
}

I would really appreciate a comment from @tanya-kta with a pretty detailed explanation of the reason for this (probably with a picture)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.