def reorder_fermionic_modes(
    interaction_operator: str, ordering: List
) -> InteractionOperator:

    interaction_operator = load_interaction_operator(interaction_operator)

    reordered_operator = _reorder_fermionic_modes(interaction_operator, ordering)
    save_interaction_operator(reordered_operator, "reordered-operator.json")
Esempio n. 2
0
def get_fermion_number_operator(number_of_qubits: int,
                                number_of_particles: Optional[int] = None):
    """Get the number operator for the input number of qubits. Optionally, the number of particles can be passed.
    Outputs are serialized to JSON under the file: "number-operator.json"

    ARGS:
        number_of_qubits (int): The number of qubits
        number_of_particles (int): The number of particles
    """
    number_op = _get_fermion_number_operator(number_of_qubits,
                                             number_of_particles)
    save_interaction_operator(number_op, "number-operator.json")
def remove_inactive_orbitals(
    interaction_operator: str,
    n_active: Optional[int] = None,
    n_core: Optional[int] = None,
):

    interaction_operator = load_interaction_operator(interaction_operator)

    frozen_operator = _remove_inactive_orbitals(
        interaction_operator, n_active=n_active, n_core=n_core
    )

    save_interaction_operator(frozen_operator, "frozen-operator.json")
Esempio n. 4
0
def get_diagonal_component(interaction_operator: Union[InteractionOperator,
                                                       str]):
    """Get the diagonal component and remainder of an input interaction operator. Outputs are serialized to JSON
    under the files: "diagonal-operator.json" and "remainder-operator.json"

    ARGS:
        interaction_operator (Union[InteractionOperator, str]): The input interaction operator
    """
    if isinstance(interaction_operator, str):
        interaction_operator = load_interaction_operator(interaction_operator)

    diagonal_operator, remainder_operator = _get_diagonal_component(
        interaction_operator)
    save_interaction_operator(diagonal_operator, "diagonal-operator.json")
    save_interaction_operator(remainder_operator, "remainder-operator.json")
Esempio n. 5
0
def test_get_one_qubit_hydrogen_hamiltonian():

    # Define interaction hamiltonian
    h2_hamiltonian_int = InteractionOperator(constant=constant,
                                             one_body_tensor=one_body_tensor,
                                             two_body_tensor=two_body_tensor)
    save_interaction_operator(h2_hamiltonian_int, 'interaction-operator.json')

    get_one_qubit_hydrogen_hamiltonian('interaction-operator.json')
    h2_1qubit = load_qubit_operator('qubit-operator.json')
    h2_1qubit_sparse = get_sparse_operator(h2_1qubit, n_qubits=1)
    h2_1qubit_dense = h2_1qubit_sparse.toarray()
    #print(h2_1qubit_dense)

    e_1q = eigvalsh(h2_1qubit_dense)

    gs_4q = get_ground_state(get_sparse_operator(h2_hamiltonian_int))

    os.remove('interaction-operator.json')
    os.remove('qubit-operator.json')

    assert isclose(e_1q[0], gs_4q[0])
Esempio n. 6
0
def run_psi4(
    basis,
    method,
    reference,
    geometry,
    freeze_core=False,
    charge=0,
    multiplicity=1,
    save_hamiltonian=False,
    save_rdms=False,
    n_active_extract="None",
    n_occupied_extract="None",
    freeze_core_extract=False,
    nthreads=1,
    options="None",
    wavefunction="None",
):
    os.mkdir("/app/scr")
    os.environ["PSI_SCRATCH"] = "/app/scr"

    if n_active_extract == "None":
        n_active_extract = None
    if n_occupied_extract == "None":
        n_occupied_extract = None
    if options == "None":
        options = None
    else:
        if isinstance(options, str):
            options = json.loads(options)
    if wavefunction == "None":
        wavefunction = None

    with open(geometry) as f:
        geometry = json.load(f)

    res = _run_psi4(
        geometry,
        basis=basis,
        multiplicity=multiplicity,
        charge=charge,
        method=method,
        reference=reference,
        freeze_core=freeze_core,
        save_hamiltonian=save_hamiltonian,
        save_rdms=save_rdms,
        options=options,
        n_active_extract=n_active_extract,
        n_occupied_extract=n_occupied_extract,
        freeze_core_extract=freeze_core_extract,
    )

    results = res["results"]
    results["schema"] = SCHEMA_VERSION + "-energy_calc"
    with open("energycalc-results.json", "w") as f:
        f.write(json.dumps(results, indent=2))

    hamiltonian = res.get("hamiltonian", None)
    if hamiltonian is not None:
        save_interaction_operator(hamiltonian, "hamiltonian.json")

    rdms = res.get("rdms", None)
    if rdms is not None:
        save_interaction_rdm(rdms, "rdms.json")

    with open("n_alpha.txt", "w") as f:
        f.write(str(results["n_alpha"]))

    with open("n_beta.txt", "w") as f:
        f.write(str(results["n_beta"]))

    with open("n_mo.txt", "w") as f:
        f.write(str(results["n_mo"]))

    with open("n_frozen_core.txt", "w") as f:
        f.write(str(results["n_frozen_core"]))