def test_interaction_operator_interconversion(n_modes, seed):
    operator = openfermion.random_interaction_operator(n_modes,
                                                       real=False,
                                                       seed=seed)
    gates = ofc.fermionic_simulation_gates_from_interaction_operator(operator)
    other_operator = sum_of_interaction_operator_gate_generators(
        n_modes, gates)
    operator = openfermion.normal_ordered(operator)
    other_operator = openfermion.normal_ordered(other_operator)
    assert operator == other_operator
Ejemplo n.º 2
0
                             order=0,
                             algorithm=algorithm,
                             control_qubit=control))
    with pytest.raises(ValueError):
        _ = next(
            simulate_trotter(qubits,
                             hamiltonian,
                             time,
                             order=1,
                             algorithm=algorithm,
                             control_qubit=control))


@pytest.mark.parametrize('algorithm_type,hamiltonian', [
    (LINEAR_SWAP_NETWORK, openfermion.random_diagonal_coulomb_hamiltonian(2)),
    (LOW_RANK, openfermion.random_interaction_operator(2)),
    (SPLIT_OPERATOR, openfermion.random_diagonal_coulomb_hamiltonian(2)),
])
def test_trotter_misspecified_control_raises_error(algorithm_type,
                                                   hamiltonian):
    qubits = cirq.LineQubit.range(2)
    time = 2.

    algorithms = [
        algorithm_type.controlled_asymmetric(hamiltonian),
        algorithm_type.controlled_symmetric(hamiltonian)
    ]

    for algorithm in algorithms:
        if algorithm is None:
            continue