Skip to content

qiroMaxSat and maxSat should not use app_sb_phase_polynomial #516

@purva-thakre

Description

@purva-thakre

def create_maxsat_cost_operator(problem):
r"""
Creates the cost operator for an instance of the maximum satisfiability problem.
For a given cost function
.. math::
C(x) = \sum_{\alpha=1}^m C_{\alpha}(x)
the cost operator is given by $e^{-i\gamma C}$ where $C=\sum_x C(x)\ket{x}\bra{x}$.
Parameters
----------
problem : tuple(int, list[list[int]])
The number of variables, and the clauses of the maximum satisfiability problem instance.
Returns
-------
cost_operator : function
A function receiving a :ref:`QuantumVariable` and a real parameter $\gamma$.
This function performs the application of the cost operator.
"""
cost_polynomials, symbols = create_maxsat_cost_polynomials(problem)
def cost_operator(qv, gamma):
for P in cost_polynomials:
app_sb_phase_polynomial([qv], -P, symbols, t=gamma)
return cost_operator

def create_maxsat_cost_operator_reduced(problem_updated):
"""
Creates the ``cost_operator`` for the problem instance.
This operator is adjusted to consider qubits that were found to be a part of the problem solution.
Parameters
----------
problem_updated : List
Updates that happened during the QIRO routine. Consits of the updated problem, a list of Qubits which were found to be positively correlated, i.e. part of the problem solution,
and a list Qubits which were found to be negatively correlated, i.e. they contradict solution qubits in accordance with the update rules.
Returns
-------
cost_operator : function
A function receiving a :ref:`QuantumVariable` and a real parameter $\gamma$. This function performs the application of the cost operator.
"""
from qrisp.algorithms.qaoa import create_maxsat_cost_polynomials
problem = problem_updated[0]
cost_polynomials, symbols = create_maxsat_cost_polynomials(problem)
def cost_operator(qv, gamma):
for P in cost_polynomials:
if not isinstance(P, int):
app_sb_phase_polynomial([qv], -P, symbols, t=gamma)
return cost_operator

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions