Exemple #1
0
    def test_cost_layer_errors(self):
        """Tests that the cost layer is throwing the correct errors"""

        hamiltonian = [[1, 1], [1, 1]]

        with pytest.raises(ValueError, match=r"hamiltonian must be of type pennylane.Hamiltonian"):
            qaoa.cost_layer(0.1, hamiltonian)

        hamiltonian = qml.Hamiltonian([1, 1], [qml.PauliZ(0), qml.PauliX(1)])

        with pytest.raises(ValueError, match=r"hamiltonian must be written only in terms of PauliZ and Identity gates"):
            qaoa.cost_layer(0.1, hamiltonian)
Exemple #2
0
    def test_cost_layer_output(self, cost, gates):
        """Tests that the gates of the cost layer is correct"""

        gamma = 1

        with qml._queuing.OperationRecorder() as rec:
            qaoa.cost_layer(gamma, cost)

        for i, j in zip(rec.operations, gates):
            prep = [i.name, i.parameters, i.wires]
            target = [j.name, j.parameters, j.wires]

        assert prep == target
Exemple #3
0
 def qaoa_layer(gamma, alpha):
     qaoa.cost_layer(gamma, cost_h)
     qaoa.mixer_layer(alpha, mixer_h)
 def qaoa_layer(gamma, alpha):
     qaoa.cost_layer(gamma, H_cost)
     qaoa.mixer_layer(alpha, H_mixer)
Exemple #5
0
def qaoa_layer(gamma, beta):
    qaoa.cost_layer(gamma, cost_h)
    qaoa.mixer_layer(beta, mixer_h)