Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindquantum.algorithm.nisq.Max2SATAnsatz

View Source On Gitee
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.

U(β,γ)=eiβpHbeiγp2Hceiβ0Hbeiγ02HcHn

Where,

Hb=inXi,Hc=lmP(l)

Here n is the number of Boolean variables and m is the number of total clauses and P(l) is rank-one projector.

Parameters
  • clauses (list[tuple[int]]) – The Max-2-SAT structure. Every element of list is a clause represented by a tuple with length two. The element of tuple must be non-zero integer. For example, (2, -3) stands for clause x2¬x3.

  • depth (int) – The depth of Max-2-SAT ansatz. Default: 1.

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
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.