From b6d9a26d87259875be43958edc30cc618ccf2c2f Mon Sep 17 00:00:00 2001 From: grossardt <99898527+grossardt@users.noreply.github.com> Date: Sat, 20 Apr 2024 00:21:42 +0200 Subject: [PATCH] Update mode_based_mapper.py --- qiskit_nature/second_q/mappers/mode_based_mapper.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/qiskit_nature/second_q/mappers/mode_based_mapper.py b/qiskit_nature/second_q/mappers/mode_based_mapper.py index e5d76db80..79593a0a8 100644 --- a/qiskit_nature/second_q/mappers/mode_based_mapper.py +++ b/qiskit_nature/second_q/mappers/mode_based_mapper.py @@ -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: @@ -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()