ProjectQ-Framework / FermiLib

FermiLib: Open source software for analyzing fermionic quantum simulation algorithms
https://projectq.ch/
Apache License 2.0
87 stars 39 forks source link

Suggestion: use x and ~x instead of (x, 0) and (x, 1) for create/annihilate operators #41

Closed Strilanc closed 7 years ago

Strilanc commented 7 years ago

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:

The upsides are:

Strilanc commented 7 years ago

I've convinced myself this is too unpythonic to be a good idea.