Class find_embedding::chain#
-
class chain#
Public Functions
-
inline 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
-
inline chain &operator=(const vector<int> &c)#
assign this to a vector of ints.
each incoming qubit will have itself as a parent.
-
inline size_t size() const#
number of qubits in chain
-
inline size_t count(const int q) const#
returns 0 if
qis not contained inthis, 1 otherwise
-
inline int 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)
-
inline void 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)
-
inline int drop_link(const int x)#
discard and return the linking qubit for
x, or -1 if that link is not set
-
inline void set_root(const int q)#
insert the qubit
qintothis, and setqto be the root (represented as the linking qubit forlabel)
-
inline void clear()#
empty this data structure
-
inline void add_leaf(const int q, const int parent)#
add the qubit
qas a leaf, withparentas its parent
-
inline int 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
-
inline int trim_leaf(int q)#
try to delete the qubit
qfrom this chain.if
qcannot be deleted, return it; otherwise return its parent
-
inline int parent(const int q) const#
the parent of
qin this chain — which might beqbut otherwise cycles should be impossible
-
inline void 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
-
inline int refcount(const int q) const#
return the number of references that
thismakes to the qubitq— where a “reference” is an occurrence ofqas a parent or an occurrence ofqas a linking qubit / root
-
inline size_t freeze(vector<chain> &others, frozen_chain &keep)#
store this chain into a
frozen_chain, unlink all chains from this, and clear()
-
inline void thaw(vector<chain> &others, frozen_chain &keep)#
restore a
frozen_chaininto this, re-establishing links from other chains.precondition: this is empty.
-
template<typename embedding_problem_t>
inline void steal(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
-
inline void 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)
-
inline void diagnostic()#
run the diagnostic, and if it fails, report the failure to the user and throw a CorruptEmbeddingException.
the
last_opargument is used in the error message
-
inline int 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
-
class iterator#
-
inline chain(vector<int> &w, int l)#