qml.qaoa.cycle.out_flow_constraint¶
- out_flow_constraint(graph)[source]¶
Calculates the out flow constraint Hamiltonian for the maximum-weighted cycle problem.
Given a subset of edges in a directed graph, the out-flow constraint imposes that at most one edge can leave any given node, i.e., for all i:
∑j,(i,j)∈Exij≤1,where E are the edges of the graph and xij is a binary number that selects whether to include the edge (i,j).
A set of edges satisfies the out-flow constraint whenever the following Hamiltonian is minimized:
∑i∈V(douti(douti−2)I−2(douti−1)∑j,(i,j)∈EˆZij+(∑j,(i,j)∈EˆZij)2)where V are the graph vertices, douti is the outdegree of node i, and Zij is a qubit Pauli-Z matrix acting upon the qubit specified by the pair (i,j). Mapping from edges to wires can be achieved using
edges_to_wires()
.- Parameters
graph (nx.DiGraph or rx.PyDiGraph) – the directed graph specifying possible edges
- Returns
the out flow constraint Hamiltonian
- Return type
qml.Hamiltonian
- Raises
ValueError – if the input graph is not directed