Beispiel #1
0
 def cost_function(Q_program, H, n, m, entangler_map, shots, device,
                   theta):
     # pylint: disable=missing-docstring
     return eval_hamiltonian(
         Q_program, H,
         trial_circuit_ryrz(n, m, theta, entangler_map, None, False),
         shots, device).real
Beispiel #2
0
def cost_function(qp, H, n_qubits, depth, entangler_map, shots, device, theta):
    trial_circuit = trial_circuit_ryrz(n_qubits, depth, theta, entangler_map,
                                       meas_string=None, measurement=False)

    energy = eval_hamiltonian(qp, H, trial_circuit, shots, device).real

    return energy
Beispiel #3
0
    def test_eval_hamiltonian_pauli_list(self):
        """
        Test of trial_circuit_ry and eval_hamiltonian with a pauli list
        """
        ham_name = self._get_resource_path(
            "../performance/H2/H2Equilibrium.txt")
        pauli_list = Hamiltonian_from_file(ham_name)
        n = 2
        m = 6
        device = 'local_statevector_simulator'

        theta = np.array([
            -0.607547697211, -0.126136414606, -0.684606358705, 0.928714748593,
            -1.84440103405, -0.467002424077, 2.29249034315, 0.488810054396,
            0.710266990661, 1.05553444322, 0.0540731003458, 0.257953416342,
            0.588281649703, 0.885244238613, -1.01700702421, -0.133693031283,
            -0.438185501332, 0.493443494428, -0.199009119848, -1.27498360732,
            0.293494154438, 0.108950311827, 0.031726785859, 1.27263986303
        ])
        entangler_map = {0: [1]}

        energy = eval_hamiltonian(
            QuantumProgram(), pauli_list,
            trial_circuit_ry(n, m, theta, entangler_map, None, False), 1,
            device)
        np.testing.assert_almost_equal(
            -0.45295043823057191 + 3.3552033732997923e-18j, energy)
Beispiel #4
0
def cost_function(qp, H, n_qubits, depth, entangler_map, shots, device, theta):
    trial_circuit = trial_circuit_ryrz(n_qubits, depth, theta, entangler_map,
                                       meas_string=None, measurement=False)

    energy = eval_hamiltonian(qp, H, trial_circuit, shots, device).real

    return energy
    def test_eval_hamiltonian_pauli_list(self):
        """
        Test of trial_circuit_ry and eval_hamiltonian with a pauli list
        """
        ham_name = self._get_resource_path("../performance/H2/H2Equilibrium.txt")
        pauli_list = Hamiltonian_from_file(ham_name)
        n = 2
        m = 6
        device = 'local_statevector_simulator'

        theta = np.array([-0.607547697211, -0.126136414606, - 0.684606358705, 0.928714748593,
                          -1.84440103405, -0.467002424077, 2.29249034315, 0.488810054396,
                          0.710266990661, 1.05553444322, 0.0540731003458, 0.257953416342,
                          0.588281649703, 0.885244238613, -1.01700702421, -0.133693031283,
                          -0.438185501332, 0.493443494428, -0.199009119848, -1.27498360732,
                          0.293494154438, 0.108950311827, 0.031726785859, 1.27263986303])
        entangler_map = {0: [1]}

        energy = eval_hamiltonian(QuantumProgram(), pauli_list,
                                  trial_circuit_ry(n, m, theta, entangler_map, None, False), 1,
                                  device)
        np.testing.assert_almost_equal(-0.45295043823057191 + 3.3552033732997923e-18j, energy)
Beispiel #6
0
def cost_function(Q_program,H,n,m,entangler_map,shots,device,theta):

    return eval_hamiltonian(Q_program,H,trial_circuit_ry(n,m,theta,entangler_map,None,False),shots,device).real
 def cost_function(Q_program, H, n, m, entangler_map, shots, device, theta):
     # pylint: disable=missing-docstring
     return eval_hamiltonian(Q_program, H,
                             trial_circuit_ryrz(n, m, theta, entangler_map, None, False),
                             shots, device).real