SupportsTrace

class SupportsTrace(*args, **kwargs)

Bases: Protocol

The trace contract this package implements.

This is the same protocol that ffsim.SupportsTrace describes, so ffsim.trace() dispatches to the method below on any object of this package. The trace of an operator on a fixed sector preconditions expm_multiply(), which factors out exp(traceA / n) – not a correctness input, but a sizeable win in speed and accuracy for an operator with a large trace, as a molecular Hamiltonian has.

>>> from qiskit_fermions.operators import FermionOperator
>>> num_op = FermionOperator.from_dict({((True, 0), (False, 0)): 1.0})
>>> num_op._trace_(norb=2, nelec=1)
(1+0j)

Protocol Methods

_trace_(norb, nelec)

Returns the trace of this operator on the (norb, nelec) FCI sector.

Parameters:
Return type:

complex