Skip to content

TwoLocal

A builder for the TwoLocal ansatz

Source code in q3as/algo/vqe.py
class TwoLocal:
    """
    A builder for the TwoLocal ansatz
    """

    def __init__(self, postprocess: _PostProcessCallable = None, **kwargs):
        """
        Create a new TwoLocal builder. Arguments are passed to the TwoLocal constructor in the Qiskit circuit library.
        """
        self.postprocess = postprocess
        self.kwargs = kwargs

    def __call__(self, obs: ObservablesArray) -> QuantumCircuit:
        ansatz = TwoLocalAnsatz(_observables_to_pauli(obs).num_qubits, **self.kwargs)
        if self.postprocess is not None:
            ansatz = self.postprocess(ansatz)
        return ansatz

__init__(postprocess=None, **kwargs)

Create a new TwoLocal builder. Arguments are passed to the TwoLocal constructor in the Qiskit circuit library.

Source code in q3as/algo/vqe.py
def __init__(self, postprocess: _PostProcessCallable = None, **kwargs):
    """
    Create a new TwoLocal builder. Arguments are passed to the TwoLocal constructor in the Qiskit circuit library.
    """
    self.postprocess = postprocess
    self.kwargs = kwargs