Skip to content

Commit

Permalink
Update mode_based_mapper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
grossardt committed Apr 19, 2024
1 parent 22b8c26 commit b6d9a26
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions qiskit_nature/second_q/mappers/mode_based_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def sparse_pauli_operators(
# pylint: disable=unused-argument
"""Generates the :class:`.SparsePauliOp` terms.
This uses :meth:`.QubitMapper.pauli_table` to construct a list of operators used to
This uses :meth:`.pauli_table` to construct a list of operators used to
translate the second-quantization symbols into qubit operators.
Args:
Expand Down Expand Up @@ -113,22 +113,21 @@ def mode_based_mapping(
register_length = second_q_op.register_length

times_creation_op, times_annihilation_op = self.sparse_pauli_operators(register_length)
mapped_string_length = times_creation_op[0].num_qubits

# make sure ret_op_list is not empty by including a zero op
ret_op_list = [SparsePauliOp("I" * register_length, coeffs=[0])]
ret_op_list = [SparsePauliOp("I" * mapped_string_length, coeffs=[0])]

for terms, coeff in second_q_op.terms():
# 1. Initialize an operator list with the identity scaled by the `coeff`
ret_op = SparsePauliOp("I" * register_length, coeffs=np.array([coeff]))
ret_op = SparsePauliOp("I" * mapped_string_length, coeffs=np.array([coeff]))

# Go through the label and replace the fermion operators by their qubit-equivalent, then
# save the respective Pauli string in the pauli_str list.
for term in terms:
char = term[0]
if char == "":
break
position = int(term[1])
if char == "+":
if char in ("+", ""): # "" for MajoranaOp, creator = annihilator
ret_op = ret_op.compose(times_creation_op[position], front=True).simplify()
elif char == "-":
ret_op = ret_op.compose(times_annihilation_op[position], front=True).simplify()
Expand Down

0 comments on commit b6d9a26

Please sign in to comment.