Assuming modes must be non-negative integers, the bitwise complement will be unambiguous and significantly easier to read/write/code.
For example:
def get_fermion_operator(interaction_operator):
n_qubits = count_qubits(interaction_operator)
identity_term = FermionOperator((), interaction_operator.constant)
one_body_terms = FermionOperator.sum(
FermionOperator.ladder(~p, q, # annihilate p, create q
coefficient=interaction_operator[p, q])
for p, q in itertools.product(range(n_qubits), repeat=2)
)
two_body_terms = FermionOperator.sum(
FermionOperator.ladder(~p, ~q, r, s, # annihilate p, annihilate q, create r, create s
coefficient=interaction_operator[p, q, r, s])
for p, q, r, s in itertools.product(range(n_qubits), repeat=4)
)
return identity_term + one_body_terms + two_body_terms
The downsides here are:
~ looks like -, so typos will be hard to spot and misreadings are somewhat likely.
Mistakes go from fail-fast to fail-sneaky. If you accidentally create ((p, 0), 1) the code will probably fail, but accidentally creating ~~p will likely run to completion and create garbage. The -p instead of ~p typo is also at high risk to make something that almost works and eats an hour of your time to debug it.
Assuming modes must be non-negative integers, the bitwise complement will be unambiguous and significantly easier to read/write/code.
For example:
The downsides here are:
~
looks like-
, so typos will be hard to spot and misreadings are somewhat likely.((p, 0), 1)
the code will probably fail, but accidentally creating~~p
will likely run to completion and create garbage. The-p
instead of~p
typo is also at high risk to make something that almost works and eats an hour of your time to debug it.The upsides are: