Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improvements #15

Merged
merged 24 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
570d6ae
[Cpp] Mistakes were made...
keksklauer4 Apr 10, 2022
a4ca639
[Cpp] Adding image feature for last iteration.
keksklauer4 Apr 10, 2022
aafa54d
[Cpp] Improving reducer.
keksklauer4 Apr 11, 2022
23aefb5
[Cpp] Fixed minor bug.
keksklauer4 Apr 11, 2022
757183f
[Cpp] Fixing reducer bugs.
keksklauer4 Apr 12, 2022
e76b626
[Cpp] Measuring execution time.
keksklauer4 Apr 12, 2022
8a9594f
[Cpp] Integrating evo reducer into main suite.
keksklauer4 Apr 12, 2022
5a95e32
[Cpp] Testing times and starting to improve ns reduction.
keksklauer4 Apr 16, 2022
5522a2e
[Cpp] Improved ns reduction.
keksklauer4 Apr 16, 2022
e66bddf
[Cpp] Added thread pool
keksklauer4 Apr 16, 2022
6d7b533
Merge branch 'develop' into feature/improvements
keksklauer4 Apr 16, 2022
33059c0
[Cpp] Better stats.
keksklauer4 Apr 18, 2022
57bbff8
[Cpp] More parallelization.
keksklauer4 Apr 18, 2022
8b494f6
[Cpp] Minor changes.
keksklauer4 Apr 19, 2022
ad73ad1
[Cpp] Replace through network simplex.
keksklauer4 Apr 20, 2022
b2d0ba5
[Cpp] Started LMRP heuristic.
keksklauer4 Apr 20, 2022
8eb1a76
[Cpp] Working on LMRP heuristic
keksklauer4 Apr 21, 2022
69a51e0
[Cpp] Working on LMRP heuristic.
keksklauer4 Apr 22, 2022
2db8d4c
[Cpp] Progressing with LMRP heuristic.
keksklauer4 Apr 22, 2022
a794065
LMRP heuristic
keksklauer4 Apr 29, 2022
ff0856a
[Cpp] Working on LMRP heuristic and related chimera subgraph locking.
keksklauer4 Apr 30, 2022
46329bf
[Cpp] Starting to test lmrp heuristic.
keksklauer4 Apr 30, 2022
f0ede08
[Cpp] Debugging lmrp heuristic.
keksklauer4 May 1, 2022
890f718
[Cpp] Fixed most lmrp bugs.
keksklauer4 May 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "external/eigen"]
path = external/eigen
url = https://gitlab.com/libeigen/eigen.git
[submodule "external/thread-pool"]
path = external/thread-pool
url = https://github.com/bshoshany/thread-pool
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ option(MAJORMINER_BUILD_TESTS "Build majorminer test executable" ON)
enable_language(C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE Debug)
set(MM_INCLUDE_LIBS external/oneTBB/include external/eigen build/external/lemon/ external/lemon/ src/)
set(CMAKE_BUILD_TYPE Release)
set(MM_INCLUDE_LIBS external/oneTBB/include external/eigen build/external/lemon/ external/lemon/ external/ src/)
set(MM_LINK_LIBS TBB::tbb lemon)

# neither build tests nor tbbmalloc in oneTBB
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ make
#### [GoogleTest](https://github.com/google/googletest) (License: [BSD 3-Clause "New" or "Revised"](https://choosealicense.com/licenses/bsd-3-clause/))
#### [LEMON](https://lemon.cs.elte.hu/trac/lemon) (License: [Boost Software License 1.0](https://choosealicense.com/licenses/bsl-1.0/))
#### [Eigen](https://eigen.tuxfamily.org/index.php?title=Main_Page) (License: [MPL2](https://choosealicense.com/licenses/mpl-2.0/), disabled LGPL features.)
#### [thread-pool](https://github.com/bshoshany/thread-pool) (License: [MIT](https://choosealicense.com/licenses/mit/))

1 change: 1 addition & 0 deletions external/thread-pool
Submodule thread-pool added at b6cd77
2 changes: 2 additions & 0 deletions img/chimera_clique_31_653.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions img/chimera_clique_33_767.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions img/chimera_clique_34_799.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions include/majorminer_lib.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#ifndef __MAJORMINER_MAJORMINER_LIB_HPP_
#define __MAJORMINER_MAJORMINER_LIB_HPP_

#include <majorminer_types.hpp>

#include <src/majorminer.hpp>

#include <src/common/embedding_analyzer.hpp>
#include <src/common/graph_info.hpp>
#include <src/common/embedding_validator.hpp>
#include <src/common/embedding_visualizer.hpp>
#include <src/lmrp/lmrp_king_subgraph.hpp>
#include <src/lmrp/lmrp_chimera_subgraph.hpp>

#endif
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

add_subdirectory(common)
add_subdirectory(lmrp)
add_subdirectory(evolutionary)
add_subdirectory(initial)

Expand Down
2 changes: 2 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ target_sources(majorminer PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/embedding_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/csc_problem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/random_gen.cpp
${CMAKE_CURRENT_SOURCE_DIR}/time_measurement.cpp
${CMAKE_CURRENT_SOURCE_DIR}/graph_info.cpp
)
28 changes: 27 additions & 1 deletion src/common/debug_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <common/debug_utils.hpp>
#include <common/utils.hpp>

#include <algorithm>

using namespace majorminer;

Expand Down Expand Up @@ -31,4 +34,27 @@ void majorminer::printVertexNumberMap(const VertexNumberMap& m)
std::cout << "(" << p.first << ", " << p.second << ") ";
}
std::cout << std::endl;
}
}

embedding_mapping_t majorminer::getReverseMapping(const embedding_mapping_t& mapping)
{
embedding_mapping_t reverse{};
for (const auto& mapped : mapping) reverse.insert(reversePair(mapped));
return reverse;
}

void majorminer::printEmbeddingOverlapStats(const embedding_mapping_t& mapping)
{
VertexNumberMap overlapStat{};
embedding_mapping_t reverse = getReverseMapping(mapping);
for (const auto& rev : reverse)
{
if(reverse.count(rev.first) > 1) overlapStat[rev.second]++;
}
Vector<fuint32_pair_t> stats{};
stats.reserve(overlapStat.size());
for (const auto& p : overlapStat) stats.push_back(reversePair(p));
std::sort(stats.begin(), stats.end(), PairFirstKeySorter<fuint32_t, fuint32_t, true>());
for (const auto& stat : stats) std::cout << "Source vertex " << stat.second << " is mapped onto " << stat.first << " vertices." << std::endl;
}

4 changes: 4 additions & 0 deletions src/common/debug_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace majorminer
void printNodeset(const nodeset_t& nodeset);

void printVertexNumberMap(const VertexNumberMap& m);

embedding_mapping_t getReverseMapping(const embedding_mapping_t& mapping);

void printEmbeddingOverlapStats(const embedding_mapping_t& mapping);
}

#endif
11 changes: 11 additions & 0 deletions src/common/embedding_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <majorminer_types.hpp>
#include <common/embedding_base.hpp>
#include <common/thread_manager.hpp>
#include <lmrp/lmrp_subgraph.hpp>

namespace majorminer
{
Expand All @@ -29,6 +31,9 @@ namespace majorminer

int getSourceNbFreeNeighbors(fuint32_t sourceNode) const;

ThreadManager& getThreadManager() { return m_threadManager; }
void setLMRPSubgraphGenerator(LMRPSubgraph* gen) { m_lmrpGen = gen; }

public: // getter
const graph_t* getSourceGraph() const override { return m_sourceGraph; }
const graph_t* getTargetGraph() const override { return m_targetGraph; }
Expand All @@ -55,6 +60,8 @@ namespace majorminer

fuint32_t getNumberSourceVertices() const { return m_numberSourceVertices; }

LMRPSubgraph* getSubgraphGen() { return m_lmrpGen; }

private:
void initialize();
void unmapNode(vertex_t sourceVertex);
Expand All @@ -77,6 +84,10 @@ namespace majorminer
fuint32_t m_numberSourceVertices;

EmbeddingVisualizer* m_visualizer;

LMRPSubgraph* m_lmrpGen;

ThreadManager m_threadManager;
};

}
Expand Down
15 changes: 15 additions & 0 deletions src/common/graph_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <common/graph_info.hpp>

using namespace majorminer;

fuint32_t ChimeraGraphInfo::getXCoord(vertex_t vertex) const
{
return (vertex % (m_width * 8)) / 8;
}

fuint32_t ChimeraGraphInfo::getYCoord(vertex_t vertex) const
{
return vertex / (m_width * 8);
}


43 changes: 43 additions & 0 deletions src/common/graph_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef __MAJORMINER_GRAPH_INFO_HPP_
#define __MAJORMINER_GRAPH_INFO_HPP_

#include <majorminer_types.hpp>

namespace majorminer
{

struct ChimeraGraphInfo
{
ChimeraGraphInfo(): m_width(0), m_height(0) {}
ChimeraGraphInfo(fuint32_t width, fuint32_t height)
: m_width(width), m_height(height) {}

fuint32_t getXCoord(vertex_t vertex) const;
fuint32_t getYCoord(vertex_t vertex) const;
fuint32_t getWidth() const { return m_width; }
fuint32_t getHeight() const { return m_height; }

fuint32_t m_width;
fuint32_t m_height;
};

struct KingGraphInfo
{
KingGraphInfo(): m_width(0), m_height(0) {}
KingGraphInfo(fuint32_t width, fuint32_t height)
: m_width(width), m_height(height) {}

fuint32_t getXCoord(vertex_t vertex) const { return vertex % m_width; }
fuint32_t getYCoord(vertex_t vertex) const { return vertex / m_width; }
fuint32_t getWidth() const { return m_width; }
fuint32_t getHeight() const { return m_height; }

fuint32_t m_width;
fuint32_t m_height;
};
}




#endif
Empty file added src/common/thread_manager.cpp
Empty file.
39 changes: 39 additions & 0 deletions src/common/thread_manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef __MAJORMINER_THREAD_MANAGER_HPP_
#define __MAJORMINER_THREAD_MANAGER_HPP_

#include <majorminer_types.hpp>
#include <thread-pool/thread_pool.hpp>

namespace majorminer
{

class ThreadManager
{
public:
ThreadManager(){}

fuint32_t getAvailableThreads() const { return m_pool.get_thread_count(); }

template<typename Functor>
void runMultiple(const Functor& func, fuint32_t n)
{
for (fuint32_t i = 0; i < n; ++i) m_pool.push_task(func);
}

template<typename Functor>
void run(const Functor& func)
{
m_pool.push_task(func);
}

void wait() { m_pool.wait_for_tasks(); }

private:
thread_pool m_pool;

};

}


#endif
9 changes: 9 additions & 0 deletions src/common/time_measurement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "common/time_measurement.hpp"

namespace majorminer
{

double TIME_MUTATION = 0, TIME_REDUCE = 0;
double GENERATE_POP = 0, OPTIMIZE = 0;

}
23 changes: 23 additions & 0 deletions src/common/time_measurement.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef __MAJORMINER_TIME_MEASUREMENT_HPP_
#define __MAJORMINER_TIME_MEASUREMENT_HPP_

#include <chrono>

#define CHRONO_STUFF(t1, t2, diff, var, ...) \
auto t1 = std::chrono::high_resolution_clock::now(); \
__VA_ARGS__ \
auto t2 = std::chrono::high_resolution_clock::now(); \
std::chrono::duration<double> diff = t2 - t1; \
var+=diff.count();


#define PRINT_TIME(name) std::cout << "Time: " << #name << ": " << name << std::endl;

namespace majorminer
{
extern double TIME_MUTATION, TIME_REDUCE;
extern double GENERATE_POP, OPTIMIZE;
}


#endif
19 changes: 18 additions & 1 deletion src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fuint32_pair_t majorminer::calculateOverlappingStats(const EmbeddingBase& base)
return std::make_pair(distinct, total);
}

embedding_mapping_t majorminer::replaceMapping(const embedding_mapping_t& mapping,
embedding_mapping_t majorminer::replaceMapping(const embedding_mapping_t& mapping,
const nodeset_t& targets, vertex_t source)
{
embedding_mapping_t adjusted{};
Expand All @@ -66,3 +66,20 @@ embedding_mapping_t majorminer::replaceMapping(const embedding_mapping_t& mappin
}
return adjusted;
}

fuint32_t majorminer::calculateFitness(const EmbeddingBase& state, const nodeset_t& superVertex)
{
const auto& reverse = state.getReverseMapping();
fuint32_t fitness = 0;
for (vertex_t target : superVertex)
{
fitness += reverse.count(target);
}
return fitness;
}

bool majorminer::containsEdge(const graph_t& graph, edge_t edge)
{
return graph.contains(orderedPair(edge));
}

27 changes: 27 additions & 0 deletions src/common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@ namespace majorminer
// inefficient - just for visualization
embedding_mapping_t replaceMapping(const embedding_mapping_t& mapping,
const nodeset_t& targets, vertex_t source);

template<typename K, typename V>
inline std::pair<V, K> reversePair(const std::pair<K,V>& p)
{
return std::make_pair(p.second, p.first);
}

template<typename K, typename V, bool reverse = false>
struct PairFirstKeySorter
{
bool operator()(const std::pair<K,V>& p1, const std::pair<K,V>& p2)
{
if(reverse) return p1.first < p2.first;
else return p1.first > p2.first;
}
};

// Calculate the fitness of an *unmapped* super vertex! Calculate number of overlappings
fuint32_t calculateFitness(const EmbeddingBase& state, const nodeset_t& superVertex);

bool containsEdge(const graph_t& graph, edge_t edge);

template<typename A, typename B>
inline bool empty_range(const std::pair<A,B>& range)
{
return range.first == range.second;
}
}


Expand Down
Loading