qrisp.qaoa.QAOAProblem.compile_circuit#

QAOAProblem.compile_circuit(qarg, depth)[source]#

Compiles the circuit that is evaluated by the run method.

Parameters
qargQuantumVariable or QuantumArray

The argument the cost function is called on.

depthint

The amont of QAOA layers.

Returns
compiled_qcQuantumCircuit

The parametrized, compiled QuantumCircuit without measurements.

list[sympy.Symbol]

A list of the parameters that appear in compiled_qc.

Examples

We create a MaxCut instance and compile the circuit:

>>> from networkx import Graph
>>> G = Graph([(0,1),(1,2),(2,0)])
>>> from qrisp.qaoa import maxcut_problem
>>> from qrisp import QuantumVariable
>>> p = 5
>>> qaoa_instance = maxcut_problem(G)
>>> qarg = QuantumVariable(len(G))
>>> qrisp_qc, symbols = qaoa_instance.compile_circuit(qarg, p)
>>> print(qrisp_qc)
             ┌───┐┌────────┐┌────────┐                          »
qarg_dupl.0: ┤ H ├┤ gphase ├┤ gphase ├──■────────────────────■──»
             ├───┤└────────┘└────────┘┌─┴─┐┌──────────────┐  │  »
qarg_dupl.1: ┤ H ├────────────────────┤ X ├┤ P(2*gamma_0) ├──┼──»
             ├───┤                    └───┘└──────────────┘┌─┴─┐»
qarg_dupl.2: ┤ H ├─────────────────────────────────────────┤ X ├»
             └───┘                                         └───┘»
«                                            ┌──────────────┐   ┌────────┐   »
«qarg_dupl.0: ───────■────────────────────■──┤ Rx(2*beta_0) ├───┤ gphase ├───»
«                  ┌─┴─┐      ┌────────┐  │  └──────────────┘   └────────┘   »
«qarg_dupl.1: ─────┤ X ├──────┤ gphase ├──┼─────────■────────────────────────»
«             ┌────┴───┴─────┐└────────┘┌─┴─┐     ┌─┴─┐      ┌──────────────┐»
«qarg_dupl.2: ┤ P(2*gamma_0) ├──────────┤ X ├─────┤ X ├──────┤ P(2*gamma_0) ├»
«             └──────────────┘          └───┘     └───┘      └──────────────┘»
«             ┌────────┐                                          »
«qarg_dupl.0: ┤ gphase ├──────────────────■────────────────────■──»
«             └────────┘┌──────────────┐┌─┴─┐┌──────────────┐  │  »
«qarg_dupl.1: ────■─────┤ Rx(2*beta_0) ├┤ X ├┤ P(2*gamma_1) ├──┼──»
«               ┌─┴─┐   ├──────────────┤└───┘└──────────────┘┌─┴─┐»
«qarg_dupl.2: ──┤ X ├───┤ Rx(2*beta_0) ├─────────────────────┤ X ├»
«               └───┘   └──────────────┘                     └───┘»
«                                            ┌──────────────┐   ┌────────┐   »
«qarg_dupl.0: ───────■────────────────────■──┤ Rx(2*beta_1) ├───┤ gphase ├───»
«                  ┌─┴─┐      ┌────────┐  │  └──────────────┘   └────────┘   »
«qarg_dupl.1: ─────┤ X ├──────┤ gphase ├──┼─────────■────────────────────────»
«             ┌────┴───┴─────┐└────────┘┌─┴─┐     ┌─┴─┐      ┌──────────────┐»
«qarg_dupl.2: ┤ P(2*gamma_1) ├──────────┤ X ├─────┤ X ├──────┤ P(2*gamma_1) ├»
«             └──────────────┘          └───┘     └───┘      └──────────────┘»
«             ┌────────┐                                          »
«qarg_dupl.0: ┤ gphase ├──────────────────■────────────────────■──»
«             └────────┘┌──────────────┐┌─┴─┐┌──────────────┐  │  »
«qarg_dupl.1: ────■─────┤ Rx(2*beta_1) ├┤ X ├┤ P(2*gamma_2) ├──┼──»
«               ┌─┴─┐   ├──────────────┤└───┘└──────────────┘┌─┴─┐»
«qarg_dupl.2: ──┤ X ├───┤ Rx(2*beta_1) ├─────────────────────┤ X ├»
«               └───┘   └──────────────┘                     └───┘»
«                                            ┌──────────────┐   ┌────────┐   »
«qarg_dupl.0: ───────■────────────────────■──┤ Rx(2*beta_2) ├───┤ gphase ├───»
«                  ┌─┴─┐      ┌────────┐  │  └──────────────┘   └────────┘   »
«qarg_dupl.1: ─────┤ X ├──────┤ gphase ├──┼─────────■────────────────────────»
«             ┌────┴───┴─────┐└────────┘┌─┴─┐     ┌─┴─┐      ┌──────────────┐»
«qarg_dupl.2: ┤ P(2*gamma_2) ├──────────┤ X ├─────┤ X ├──────┤ P(2*gamma_2) ├»
«             └──────────────┘          └───┘     └───┘      └──────────────┘»
«             ┌────────┐                                          »
«qarg_dupl.0: ┤ gphase ├──────────────────■────────────────────■──»
«             └────────┘┌──────────────┐┌─┴─┐┌──────────────┐  │  »
«qarg_dupl.1: ────■─────┤ Rx(2*beta_2) ├┤ X ├┤ P(2*gamma_3) ├──┼──»
«               ┌─┴─┐   ├──────────────┤└───┘└──────────────┘┌─┴─┐»
«qarg_dupl.2: ──┤ X ├───┤ Rx(2*beta_2) ├─────────────────────┤ X ├»
«               └───┘   └──────────────┘                     └───┘»
«                                            ┌──────────────┐   ┌────────┐   »
«qarg_dupl.0: ───────■────────────────────■──┤ Rx(2*beta_3) ├───┤ gphase ├───»
«                  ┌─┴─┐      ┌────────┐  │  └──────────────┘   └────────┘   »
«qarg_dupl.1: ─────┤ X ├──────┤ gphase ├──┼─────────■────────────────────────»
«             ┌────┴───┴─────┐└────────┘┌─┴─┐     ┌─┴─┐      ┌──────────────┐»
«qarg_dupl.2: ┤ P(2*gamma_3) ├──────────┤ X ├─────┤ X ├──────┤ P(2*gamma_3) ├»
«             └──────────────┘          └───┘     └───┘      └──────────────┘»
«             ┌────────┐                                          »
«qarg_dupl.0: ┤ gphase ├──────────────────■────────────────────■──»
«             └────────┘┌──────────────┐┌─┴─┐┌──────────────┐  │  »
«qarg_dupl.1: ────■─────┤ Rx(2*beta_3) ├┤ X ├┤ P(2*gamma_4) ├──┼──»
«               ┌─┴─┐   ├──────────────┤└───┘└──────────────┘┌─┴─┐»
«qarg_dupl.2: ──┤ X ├───┤ Rx(2*beta_3) ├─────────────────────┤ X ├»
«               └───┘   └──────────────┘                     └───┘»
«                                            ┌──────────────┐                »
«qarg_dupl.0: ───────■────────────────────■──┤ Rx(2*beta_4) ├────────────────»
«                  ┌─┴─┐      ┌────────┐  │  └──────────────┘                »
«qarg_dupl.1: ─────┤ X ├──────┤ gphase ├──┼─────────■────────────────────────»
«             ┌────┴───┴─────┐└────────┘┌─┴─┐     ┌─┴─┐      ┌──────────────┐»
«qarg_dupl.2: ┤ P(2*gamma_4) ├──────────┤ X ├─────┤ X ├──────┤ P(2*gamma_4) ├»
«             └──────────────┘          └───┘     └───┘      └──────────────┘»
«                                  
«qarg_dupl.0: ─────────────────────
«                  ┌──────────────┐
«qarg_dupl.1: ──■──┤ Rx(2*beta_4) ├
«             ┌─┴─┐├──────────────┤
«qarg_dupl.2: ┤ X ├┤ Rx(2*beta_4) ├
«             └───┘└──────────────┘