mindquantum.algorithm.nisq.Max2SATAnsatz
- class mindquantum.algorithm.nisq.Max2SATAnsatz(clauses, depth=1)[source]
The Max-2-SAT ansatz.
For more detail, please refer to Reachability Deficits in Quantum Approximate Optimization.
Where,
Here
is the number of Boolean variables and is the number of total clauses and is rank-one projector.- Parameters
Examples
>>> import numpy as np >>> from mindquantum.algorithm.nisq import Max2SATAnsatz >>> clauses = [(2, -3)] >>> max2sat = Max2SATAnsatz(clauses, 1) >>> max2sat.circuit ┏━━━┓ ┏━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━┓ q1: ──┨ H ┠─┨ RZ(1/2*gamma_0) ┠────■──────────────────────────■───┨ RX(beta_0) ┠─── ┗━━━┛ ┗━━━━━━━━━━━━━━━━━┛ ┃ ┃ ┗━━━━━━━━━━━━┛ ┏━━━┓ ┏━━━━━━━━━━━━━━━━━━┓ ┏━┻━┓ ┏━━━━━━━━━━━━━━━━━━┓ ┏━┻━┓ ┏━━━━━━━━━━━━┓ q2: ──┨ H ┠─┨ RZ(-1/2*gamma_0) ┠─┨╺╋╸┠─┨ RZ(-1/2*gamma_0) ┠─┨╺╋╸┠─┨ RX(beta_0) ┠─── ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━┛ ┗━━━┛ ┗━━━━━━━━━━━━━━━━━━┛ ┗━━━┛ ┗━━━━━━━━━━━━┛ >>> max2sat.hamiltonian 1/4 [] + 1/4 [Z1] + -1/4 [Z1 Z2] + -1/4 [Z2] >>> sats = max2sat.get_sat(4, np.array([4, 1])) >>> sats ['001', '000', '011', '010'] >>> for i in sats: ... print(f'sat value: {max2sat.get_sat_value(i)}') sat value: 1 sat value: 0 sat value: 2 sat value: 1
- get_sat(max_n, weight)[source]
Get the strings of this max-2-sat problem.
- Parameters
max_n (int) – how many strings you want.
weight (Union[ParameterResolver, dict, numpy.ndarray, list, numbers.Number]) – parameter value for Max-2-SAT ansatz.
- Returns
list, a list of strings.
- get_sat_value(string)[source]
Get the sat values for given strings.
The string is a str that satisfies all the clauses of the given max-2-sat problem.
- Parameters
string (str) – a string of the max-2-sat problem considered.
- Returns
int, sat_value under the given string.
- property hamiltonian
Get the hamiltonian of this max-2-sat problem.
- Returns
QubitOperator, hamiltonian of this max-2-sat problem.