Namespace find_embedding¶
-
namespace
find_embedding Typedefs
-
using
find_embedding::distance_t = typedef long long int
-
using
find_embedding::RANDOM = typedef default_random_engine
-
using
find_embedding::clock = typedef std::chrono::high_resolution_clock
-
using
find_embedding::distance_queue = typedef pairing_queue::pairing_queue_fast_reset<distance_t>
-
using
find_embedding::int_queue = typedef pairing_queue::pairing_queue_fast_reset<int64_t>
-
typedef shared_ptr<LocalInteraction> find_embedding
LocalInteractionPtr
Enums
-
enum find_embedding
VARORDER Values:
-
find_embedding
VARORDER_SHUFFLE
-
find_embedding
VARORDER_DFS
-
find_embedding
VARORDER_BFS
-
find_embedding
VARORDER_PFS
-
find_embedding
VARORDER_RPFS
-
find_embedding
VARORDER_KEEP
-
find_embedding
Functions
-
template <class pathfinder_t>
int find_embeddingfind_embedding_execute(graph::input_graph &var_g, graph::input_graph &qubit_g, optional_parameters ¶ms_, vector<vector<int>> &chains) This function parses inputs, scrambles node labels, dispatches the main embedding algorithm, pathfinder_base.heuristicEmbedding, and finally unscrambles the resulting answer.
-
int find_embedding
findEmbedding(graph::input_graph &var_g, graph::input_graph &qubit_g, optional_parameters ¶ms_, vector<vector<int>> &chains) The main entry function of this library.
This method primarily dispatches the proper implementation of the algorithm where some parameters/behaviours have been fixed at compile time.
In terms of dispatch, there are three dynamically-selected classes which are combined, each according to a specific optional parameter.
- a domain_handler, described in embedding_problem.hpp, manages constraints of the form “variable a’s chain must be a subset of…”
- a fixed_handler, described in embedding_problem.hpp, manages contstraints of the form “variable a’s chain must be exactly…”
- a pathfinder, described in pathfinder.hpp, which come in two flavors, serial and parallel The optional parameters themselves can be found in util.hpp. Respectively, the controlling options for the above are restrict_chains, fixed_chains, and threads.
-
template <typename T>
void find_embeddingcollectMinima(const vector<T> &input, vector<int> &output) Fill output with the index of all of the minimum and equal values in input.
Variables
-
constexpr distance_t find_embedding
max_distance= numeric_limits<distance_t>::max()
-
class find_embedding
chain - #include <chain.hpp>
This class stores chains for embeddings, and performs qubit-use accounting.
The
labelis the index number for the variable represented by this chain. Thelinksmember of a chain is an unordered map storing the linking information for this chain. Thedatamember of a chain stores the connectivity information for the chain.Links: If
uandvare variables which are connected by an edge, the following must be true: either chain_u or chain_v is empty,or
chain_u.links[v] is a key in chain_u.data, chain_v.links[u] is a key in chain_v.data, and (chain_u.links[v], chain_v.links[u]) are adjacent in the qubit graph
Moreover, (chain_u.links[u]) must exist if chain_u is not empty, and this is considered the root of the chain.
Data: The
datamember stores the connectivity information. More precisely,datais a mappingqubit->(parent, refs)where:parentis also contained in the chainrefsis the total number of references toqubit, counting both parents and links the chain root is its own parent.Public Functions
-
find_embedding::chain
chain(vector<int> &w, int l) construct this chain, linking it to the qubit_weight vector
w(common to all chains in an embedding, typically) and setting its variable labell
-
chain &find_embedding::chain
operator=(const vector<int> &c) assign this to a vector of ints.
each incoming qubit will have itself as a parent.
-
chain &find_embedding::chain
operator=(const chain &c)¶ assign this to another chain
-
int find_embedding::chain
size() const number of qubits in chain
-
int find_embedding::chain
count(const int q) const returns 0 if
qis not contained inthis, 1 otherwise
-
int find_embedding::chain
get_link(const int x) const get the qubit, in
this, which linksthisto the chain of x (if x==label, interpret the linking qubit as the chain’s root)
-
void find_embedding::chain
set_link(const int x, const int q) set the qubit, in
this, which linksthisto the chain of x (if x==label, interpret the linking qubit as the chain’s root)
-
int find_embedding::chain
drop_link(const int x) discard and return the linking qubit for
x, or -1 if that link is not set
-
void find_embedding::chain
set_root(const int q) insert the qubit
qintothis, and setqto be the root (represented as the linking qubit forlabel)
-
void find_embedding::chain
clear() empty this data structure
-
void find_embedding::chain
add_leaf(const int q, const int parent) add the qubit
qas a leaf, withparentas its parent
-
int find_embedding::chain
trim_branch(int q) try to delete the qubit
qfrom this chain, and keep deleting until no more qubits are free to be deleted.return the first ancestor which cannot be deleted
-
int find_embedding::chain
trim_leaf(int q) try to delete the qubit
qfrom this chain.if
qcannot be deleted, return it; otherwise return its parent
-
int find_embedding::chain
parent(const int q) const the parent of
qin this chain which might beqbut otherwise cycles should be impossible
-
void find_embedding::chain
adopt(const int p, const int q) assign
pto be the parent ofq, on condition that bothpandqare contained inthis,qis its own parent, andqis not the root
-
int find_embedding::chain
refcount(const int q) const return the number of references that
thismakes to the qubitqwhere a “reference” is an occurrence ofqas a parent or an occurrence ofqas a linking qubit / root
-
template <typename embedding_problem_t>
void find_embedding::chainsteal(chain &other, embedding_problem_t &ep, int chainsize = 0) assumes
thisandotherhave links for eachother’s labels steals all qubits fromotherwhich are available to be taken bythis; starting with the qubit links and updating qubit links after all
-
void find_embedding::chain
link_path(chain &other, int q, const vector<int> &parents) link this chain to another, following the path
q,parent[q],parent[parent[q]], …from
thistootherand intermediate nodes (all but the last) intothis(preconditions:thisandotherare not linked,qis contained inthis, and the parent-path is eventually contained inother)
-
iterator find_embedding::chain
begin() const iterator pointing to the first qubit in this chain
-
iterator find_embedding::chain
end() const iterator pointing to the end of this chain
-
void find_embedding::chain
diagnostic(char *last_op) run the diagnostic, and if it fails, report the failure to the user and throw -1.
the
last_opargument is used in the error message
-
int find_embedding::chain
run_diagnostic() const run the diagnostic and return a nonzero status
rin case of failure if(r&1), then the parent of a qubit is not contained in this chain if(r&2), then there is a refcounting error in this chain
-
find_embedding::chain
-
class find_embedding
domain_handler_masked - #include <embedding_problem.hpp>
this domain handler stores masks for each variable so that prepare_visited and prepare_distances are barely more expensive than a memcopy
-
class find_embedding
domain_handler_universe - #include <embedding_problem.hpp>
this is the trivial domain handler, where every variable is allowed to use every qubit
-
template <typename embedding_problem_t>
class find_embeddingembedding - #include <embedding.hpp>
This class is how we represent and manipulate embedding objects, using as much encapsulation as possible.
We provide methods to view and modify chains.
Public Functions
-
find_embedding::embedding
embedding(embedding_problem_t &e_p) constructor for an empty embedding
-
find_embedding::embedding
embedding(embedding_problem_t &e_p, map<int, vector<int>> &fixed_chains, map<int, vector<int>> &initial_chains)¶ constructor for an initial embedding: accepts fixed and initial chains, populates the embedding based on them, and attempts to link adjacent chains together.
-
embedding<embedding_problem_t> &find_embedding::embedding
operator=(const embedding<embedding_problem_t> &other) copy the data from
other.var_embeddingintothis.var_embedding
-
const chain &find_embedding::embedding
get_chain(int v) const Get the variables in a chain.
-
int find_embedding::embedding
chainsize(int v) const Get the size of a chain.
-
int find_embedding::embedding
weight(int q) const Get the weight of a qubit.
-
int find_embedding::embedding
max_weight() const Get the maximum of all qubit weights.
-
int find_embedding::embedding
max_weight(const int start, const int stop) const¶ Get the maximum of all qubit weights in a range.
-
bool find_embedding::embedding
has_qubit(const int v, const int q) const Check if variable v is includes qubit q in its chain.
-
void find_embedding::embedding
set_chain(const int u, const vector<int> &incoming) Assign a chain for variable u.
-
void find_embedding::embedding
fix_chain(const int u, const vector<int> &incoming) Permanently assign a chain for variable u.
NOTE: This must be done before any chain is assigned to u.
-
bool find_embedding::embedding
operator==(const embedding &other) const check if
thisandotherhave the same chains (up to qubit containment per chain; linking and parent information is not checked)
-
void find_embedding::embedding
construct_chain(const int u, const int q, const vector<vector<int>> &parents) construct the chain for
u, rooted atq, with a vector of parent info, where for each neiborvofu, followingq->parents[v][q]->parents[v][parents[v][q]]…terminates in the chain for
v
-
void find_embedding::embedding
flip_back(int u, const int target_chainsize) distribute path segments to the neighboring chains path segments are the qubits that are ONLY used to join link_qubit[u][v] to link_qubit[u][u] and aren’t used for any other variable
- if the target chainsize is zero, dump the entire segment into the neighbor
- if the target chainsize is k, stop when the neighbor’s size reaches k
-
void find_embedding::embedding
tear_out(int u) short tearout procedure blank out the chain, its linking qubits, and account for the qubits being freed
-
void find_embedding::embedding
steal_all(int u) grow the chain for
u, stealing all available qubits from neighboring variables
-
int find_embedding::embedding
statistics(vector<int> &stats) const compute statistics for this embedding and return
1if no chains are overlapping when no chains are overlapping, populatestatswith a chainlength histogram chains do overlap, populatestatswith a qubit overfill histogram a histogram, in this case, is a vector of size (maximum attained value+1) wherestats[i]is either the number of qubits contained ini+2chains or the number of chains with sizei
-
bool find_embedding::embedding
linked() const check if the embedding is fully linked that is, if each pair of adjacent variables is known to correspond to a pair of adjacent qubits
-
bool find_embedding::embedding
linked(int u) const¶ check if a single variable is linked with all adjacent variables.
-
void find_embedding::embedding
print() const print out this embedding to a level of detail that is useful for debugging purposes TODO describe the output format.
-
void find_embedding::embedding
long_diagnostic(char *current_state) run a long diagnostic, and if debugging is enabled, record
current_stateso that the error message has a little more context.if an error is found, throw -1
-
void find_embedding::embedding
run_long_diagnostic(char *current_state) const run a long diagnostic to verify the integrity of this datastructure.
the guts of this function are its documentation, because this function only exists for debugging purposes
-
find_embedding::embedding
-
template <class fixed_handler, class domain_handler>
class find_embeddingembedding_problem: public find_embedding::embedding_problem_base, public fixed_handler, public domain_handler - #include <embedding_problem.hpp>
A template to construct a complete embedding problem by combining
embedding_problem_basewith fixed/domain handlers.
-
class find_embedding
embedding_problem_base - #include <embedding_problem.hpp>
Common form for all embedding problems.
Needs to be extended with a fixed handler and domain handler to be complete.
Subclassed by find_embedding::embedding_problem< fixed_handler, domain_handler >
Public Functions
-
const vector<int> &find_embedding::embedding_problem_base
var_neighbors(int u) const a vector of neighbors for the variable
u
-
const vector<int> &find_embedding::embedding_problem_base
qubit_neighbors(int q) const a vector of neighbors for the qubit
q
-
int find_embedding::embedding_problem_base
num_vars() const number of variables which are not fixed
-
int find_embedding::embedding_problem_base
num_qubits() const number of qubits which are not reserved
-
int find_embedding::embedding_problem_base
num_fixed() const number of fixed variables
-
int find_embedding::embedding_problem_base
num_reserved() const number of reserved qubits
-
template <typename... Args>
void find_embedding::embedding_problem_baseerror(const char *format, Args... args) const printf regardless of the verbosity level
-
template <typename... Args>
void find_embedding::embedding_problem_basemajor_info(const char *format, Args... args) const printf at the major_info verbosity level
-
template <typename... Args>
void find_embedding::embedding_problem_baseminor_info(const char *format, Args... args) const print at the minor_info verbosity level
-
template <typename... Args>
void find_embedding::embedding_problem_baseextra_info(const char *format, Args... args) const print at the extra_info verbosity level
-
template <typename... Args>
void find_embedding::embedding_problem_basedebug(const char *ONDEBUGformat, Args... ONDEBUGargs) const print at the debug verbosity level (only works when
CPPDEBUGis set)
-
int find_embedding::embedding_problem_base
randint(int m) make a random integer between 0 and
m-1
-
template <typename A, typename B>
void find_embedding::embedding_problem_baseshuffle(A a, B b) shuffle the data bracketed by iterators
aandb
-
void find_embedding::embedding_problem_base
qubit_component(int q0, vector<int> &component, vector<int> &visited) compute the connected component of the subset
componentof qubits, containingq0, and usingvisitedas an indicator for which qubits have been explored
-
const vector<int> &find_embedding::embedding_problem_base
var_order(VARORDER order = VARORDER_SHUFFLE) compute a variable ordering according to the
orderstrategy
-
void find_embedding::embedding_problem_base
dfs_component(int x, const vector<vector<int>> &neighbors, vector<int> &component, vector<int> &visited) Perform a depth first search.
Public Members
-
optional_parameters &find_embedding::embedding_problem_base
params A mutable reference to the user specified parameters.
-
const vector<int> &find_embedding::embedding_problem_base
-
class find_embedding
FindEmbeddingException - #include <util.hpp>
Subclassed by find_embedding::ProblemCancelledException
-
class find_embedding
fixed_handler_hival - #include <embedding_problem.hpp>
This fixed handler is used when the fixed variables are processed before instantiation and relabeled such that variables v >= num_v are fixed and qubits q >= num_q are reserved.
-
class find_embedding
fixed_handler_list - #include <embedding_problem.hpp>
This fixed handler is used when variables are allowed to be fixed after instantiation.
For that functionality, we probably need…
- dynamic modification of var_neighbors and qubit_neighbors to maintain speed gains: fixed variables are sinks, reserved qubits are sources.
- access to / ownership of var_neighbors and qubit_neighbors in this data structure
- move existing initialization code from find_embedding.hpp into fixed_handler_hival (note the interplay with shuffling qubit labels, this might get gross)
-
class find_embedding
fixed_handler_none - #include <embedding_problem.hpp>
This fixed handler is used when there are no fixed variables.
-
class find_embedding
LocalInteraction - #include <util.hpp>
Interface for communication between the library and various bindings.
Any bindings of this library need to provide a concrete subclass.
Public Functions
-
void find_embedding::LocalInteraction
displayOutput(const string &msg) const Print a message through the local output method.
-
bool find_embedding::LocalInteraction
cancelled(const clock::time_point stoptime) const Check if someone is trying to cancel the embedding process.
-
void find_embedding::LocalInteraction
-
class find_embedding
optional_parameters - #include <util.hpp>
Set of parameters used to control the embedding process.
Public Members
-
LocalInteractionPtr find_embedding::optional_parameters
localInteractionPtr actually not controlled by user, not initialized here, but initialized in Python, MATLAB, C wrappers level
-
double find_embedding::optional_parameters
timeout= 1000 Number of seconds before the process unconditionally stops.
-
LocalInteractionPtr find_embedding::optional_parameters
-
template <typename embedding_problem_t>
class find_embeddingpathfinder_base - #include <pathfinder.hpp>
Subclassed by find_embedding::pathfinder_parallel< embedding_problem_t >, find_embedding::pathfinder_serial< embedding_problem_t >
Public Functions
-
int find_embedding::pathfinder_base
check_improvement(const embedding_t &emb) nonzero return if this is an improvement on our previous best embedding
-
const chain &find_embedding::pathfinder_base
get_chain(int u) const chain accessor
-
int find_embedding::pathfinder_base
heuristicEmbedding() perform the heuristic embedding, returning 1 if an embedding was found and 0 otherwise
-
int find_embedding::pathfinder_base
-
template <typename embedding_problem_t>
class find_embeddingpathfinder_parallel: public find_embedding::pathfinder_base<embedding_problem_t> - #include <pathfinder.hpp>
A pathfinder where the Dijkstra-from-neighboring-chain passes are done serially.
Public Functions
-
virtual void find_embedding::pathfinder_parallel
prepare_root_distances(const embedding_t &emb, const int u) compute the distances from all neighbors of
uto all qubits
-
virtual void find_embedding::pathfinder_parallel
-
template <typename embedding_problem_t>
class find_embeddingpathfinder_serial: public find_embedding::pathfinder_base<embedding_problem_t> - #include <pathfinder.hpp>
A pathfinder where the Dijkstra-from-neighboring-chain passes are done serially.
Public Functions
-
virtual void find_embedding::pathfinder_serial
prepare_root_distances(const embedding_t &emb, const int u) compute the distances from all neighbors of
uto all qubits
-
virtual void find_embedding::pathfinder_serial
-
using