def circuit(weights):
     UCCSD(weights,
           wires,
           s_wires=s_wires,
           d_wires=d_wires,
           init_state=np.array([1, 1, 0, 0]))
     return [qml.expval(qml.PauliZ(w)) for w in range(N)]
 def circuit(w0, w1, w2):
     UCCSD(
         [w0, w1, w2],
         wires,
         s_wires=s_wires,
         d_wires=d_wires,
         init_state=np.array([1, 1, 0, 0]),
     )
     return [qml.expval(qml.PauliZ(w)) for w in range(N)]
 def circuit(
     weights=weights, wires=wires, s_wires=s_wires, d_wires=d_wires, init_state=init_state
 ):
     UCCSD(
         weights=weights,
         wires=wires,
         s_wires=s_wires,
         d_wires=d_wires,
         init_state=init_state,
     )
     return qml.expval(qml.PauliZ(0))
Exemple #4
0
    def test_uccsd_operations(self, s_wires, d_wires, weights, ref_gates):
        """Test the correctness of the UCCSD template including the gate count
        and order, the wires the operation acts on and the correct use of parameters
        in the circuit."""

        sqg = 10 * len(s_wires) + 72 * len(d_wires)

        cnots = 0
        for s_wires_ in s_wires:
            cnots += 4 * (len(s_wires_) - 1)

        for d_wires_ in d_wires:
            cnots += 16 * (len(d_wires_[0]) - 1 + len(d_wires_[1]) - 1 + 1)
        N = 6
        wires = range(N)

        ref_state = np.array([1, 1, 0, 0, 0, 0])

        with pennylane._queuing.OperationRecorder() as rec:
            UCCSD(weights,
                  wires,
                  s_wires=s_wires,
                  d_wires=d_wires,
                  init_state=ref_state)

        assert len(rec.queue) == sqg + cnots + 1

        for gate in ref_gates:
            idx = gate[0]

            exp_gate = gate[1]
            res_gate = rec.queue[idx]
            assert isinstance(res_gate, exp_gate)

            exp_wires = gate[2]
            res_wires = rec.queue[idx]._wires
            assert res_wires == Wires(exp_wires)

            exp_weight = gate[3]
            res_weight = rec.queue[idx].parameters
            if exp_gate != qml.BasisState:
                assert res_weight == exp_weight
            else:
                assert np.allclose(res_weight, exp_weight)
    def test_uccsd_operations(self, ph, pphh, weights, ref_gates):
        """Test the correctness of the UCCSD template including the gate count
        and order, the wires the operation acts on and the correct use of parameters 
        in the circuit."""

        sqg = 10*len(ph) + 72*len(pphh)

        cnots = 0
        for i_ph in ph:
            cnots += 4*(i_ph[1]-i_ph[0])

        for i_pphh in pphh:
            cnots += 16*(i_pphh[1]-i_pphh[0] + i_pphh[3]-i_pphh[2] + 1)
        N = 6
        wires = range(N)

        ref_state = np.array([1, 1, 0, 0, 0, 0])

        with qml.utils.OperationRecorder() as rec:
            UCCSD(weights, wires, ph=ph, pphh=pphh, init_state=ref_state)

        assert len(rec.queue) == sqg + cnots + 1

        for gate in ref_gates:
            idx = gate[0]

            exp_gate = gate[1]
            res_gate = rec.queue[idx]
            assert isinstance(res_gate, exp_gate)

            exp_wires = gate[2]
            res_wires = rec.queue[idx]._wires
            assert res_wires == exp_wires

            exp_weight = gate[3]
            res_weight = rec.queue[idx].parameters
            if exp_gate != qml.BasisState:
                assert res_weight == exp_weight
            else:
                assert np.allclose(res_weight, exp_weight)
 def circuit(w_ph_0, w_ph_1, w_pphh):
 	UCCSD(weights, wires, ph=ph, pphh=pphh, init_state=np.array([1, 1, 0, 0]))
 def circuit(weights=weights, wires=wires, ph=ph, pphh=pphh, init_state=init_state):
     UCCSD(weights=weights, wires=wires, ph=ph, pphh=pphh, init_state=init_state)
     return qml.expval(qml.PauliZ(0))
 def circuit(w_ph_0, w_ph_1, w_pphh):
     UCCSD([w_ph_0, w_ph_1, w_pphh], wires, ph=ph, pphh=pphh, init_state=np.array([1, 1, 0, 0]))
     return [qml.expval(qml.PauliZ(w)) for w in range(N)]
 def circuit(weights):
     UCCSD(weights, wires, ph=ph, pphh=pphh, init_state=np.array([1, 1, 0, 0]))
     return [qml.expval(qml.PauliZ(w)) for w in range(N)]