qrisp.qaoa.controlled_RX_mixer_gen#

controlled_RX_mixer_gen(predicate)[source]#

Generate a controlled RX mixer for a given predicate function.

Parameters:
predicatefunction

A function receiving a QuantumVariable and an index \(i\). This function returns a QuantumBool indicating if the predicate is satisfied for qv[i], that is, if the element qv[i] should be swapped in.

Returns:
controlled_RX_mixerfunction

A function receiving a QuantumVariable and a real parameter \(\beta\). This function performs the application of the mixing operator.

Examples

We define the predicate function for the MaxIndepSet problem. It returns True for the index (node) \(i\) if all neighbors \(j\) of the node \(i\) in the graph \(G\) are not selected, and False otherwise.

from qrisp import QuantumVariable, QuantumBool, h, mcx, auto_uncompute, multi_measurement
import networkx as nx

G = nx.Graph()
G.add_edges_from([(0, 1), (1, 2), (2, 0)])  
neighbors_dict = {node: list(G.adj[node]) for node in G.nodes()}

def predicate(qv,i):
    qbl = QuantumBool()
    if len(neighbors_dict[i])==0:
        x(qbl)
    else:
        mcx([qv[j] for j in neighbors_dict[i]],qbl,ctrl_state='0'*len(neighbors_dict[i]))
    return qbl

qv = QuantumVariable(3)
h(qv)
qbl = predicate(qv,0)
multi_measurement([qv,qbl])
# Yields: {('000', True): 0.125,('100', True): 0.125,('010', False): 0.125,('110', False): 0.125,('001', False): 0.125,('101', False): 0.125,('011', False): 0.125,('111', False): 0.125}

The resulting controlled_RX_mixer then only swaps the node \(i\) in if all neighbors \(j\) in the graph \(G\) are not selected.