fermion_ternary_tree
fermion_ternary_tree(op, encoding, num_qubits)
Map a FermionOperator to a SparseObservable under a ternary-tree encoding.
Parameters
- op – the fermionic operator to map.
- encoding – the compiled encoding to map through.
- num_qubits – the number of qubits for the resulting qubit operator. Must be at least the encoding’s mode count; a larger value pads with the identity.
Returns
The mapped qubit operator. The result is not guaranteed to be fully simplified; call simplify() to combine any remaining duplicate terms. Duplicates are merged as the result is assembled, to bound the memory required, so the exact number of terms returned may vary with the number of threads used. Any grouping carried by op is not reflected in the result, as a SparseObservable does not track groups.
Raises
- ValueError – if
opacts on a mode the encoding does not cover, ornum_qubitsis smaller than the encoding’s mode count. - OverflowError – if
num_qubitsis negative or does not fit in 32 bits.
Usage
On a chain along Z this reproduces fermion_jordan_wigner() exactly:
>>> from qiskit_fermions.mappers import TernaryTree, TernaryTreeEncoding
>>> from qiskit_fermions.mappers.library import (
... fermion_jordan_wigner, fermion_ternary_tree,
... )
>>> from qiskit_fermions.operators import FermionOperator
>>> fop = FermionOperator.from_dict({((True, 0), (False, 0)): 0.1})
>>> enc = TernaryTreeEncoding(TernaryTree.chain(2, "Z"))
>>> fermion_ternary_tree(fop, enc, 2).simplify()
<SparseObservable with 2 terms on 2 qubits: (0.05+0j)() + (-0.05+0j)(Z_0)>
>>> bool((fermion_ternary_tree(fop, enc, 2) - fermion_jordan_wigner(fop, 2)).simplify().num_terms == 0)
True
Other trees trade that encoding’s Pauli weight, linear in the number of modes, for a shallower one.
このページは役に立ちましたか?
バグや誤字の報告、またはコンテンツの要求はGitHubで行ってください。