Пример #1
0
 def circuit4(a, b, c):
     qml.RX(b, 0)
     qml.RX(c, 1)
     return qml.expval.PauliZ(0), qml.expval.PauliZ(1)
Пример #2
0
    def test_validity(self):
        """check that execution throws error on unsupported operations/observables"""
        self.logTestName()

        for dev in self.dev.values():
            ops = dev.operations
            all_ops = set(qml.ops.__all_ops__)

            for o in all_ops - ops:
                op = getattr(qml.ops, o)

                if op.par_domain == 'A':
                    # skip operations with array parameters, as there are too
                    # many constraints to consider. These should be tested
                    # directly within the plugin tests.
                    continue
                elif op.par_domain == 'N':
                    params = np.asarray(np.random.random([op.num_params]),
                                        dtype=np.int64)
                else:
                    params = np.random.random([op.num_params])

                queue = [
                    op(*params,
                       wires=list(range(op.num_wires)),
                       do_queue=False)
                ]

                temp = isinstance(queue[0], qml.operation.CV)

                with self.assertRaisesRegex(qml.DeviceError,
                                            'not supported on device'):
                    if temp:
                        expval = dev.execute(
                            queue, [qml.expval(qml.X(0, do_queue=False))])
                    else:
                        expval = dev.execute(
                            queue, [qml.expval(qml.PauliX(0, do_queue=False))])

            exps = dev.observables
            all_exps = set(qml.ops.__all_obs__)

            for g in all_exps - exps:
                op = getattr(qml.ops, g)

                if op.par_domain == 'A':
                    # skip observables with array parameters, as there are too
                    # many constraints to consider. These should be tested
                    # directly within the plugin tests.
                    continue
                elif op.par_domain == 'N':
                    params = np.asarray(np.random.random([op.num_params]),
                                        dtype=np.int64)
                else:
                    params = np.random.random([op.num_params])

                queue = [
                    op(*params,
                       wires=list(range(op.num_wires)),
                       do_queue=False)
                ]

                temp = isinstance(queue[0], qml.operation.CV)

                with self.assertRaisesRegex(qml.DeviceError,
                                            'not supported on device'):
                    if temp:
                        expval = dev.execute(
                            [qml.Rotation(0.5, wires=0, do_queue=False)],
                            queue)
                    else:
                        expval = dev.execute(
                            [qml.RX(0.5, wires=0, do_queue=False)], queue)
Пример #3
0
def quant_fun_nested(var):
    qml.RX(var[0][0][0], wires=[0])
    qml.RY(var[0][1], wires=[0])
    qml.RY(var[1][0], wires=[0])
    qml.RX(var[1][1][0], wires=[0])
    return qml.expval.PauliZ(0)
Пример #4
0
 def circuit_torch(phi, theta):
     qml.RX(phi[0], wires=0)
     qml.RY(phi[1], wires=1)
     qml.CNOT(wires=[0, 1])
     qml.PhaseShift(theta[0], wires=0)
     return qml.expval(qml.PauliZ(0))
Пример #5
0
 def qf(x):
     qml.RX(x, wires=[0])
     ex = qml.expval(qml.PauliZ(1))
     return qml.expval(qml.PauliZ(0)), ex
Пример #6
0
 def qf(x):
     qml.RX(x, wires=[0])
     qml.Displacement(0.5, 0, wires=[0])
     return qml.expval(qml.PauliZ(0))
Пример #7
0
 def circuit(w, x=None):
     qml.RX(w, wires=[0])
     qml.RX(x, wires=[1])
     return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
Пример #8
0
 def qf(x):
     qml.RX(x, [0])
     qml.Displacement(0.5, 0, [0])
     return qml.expval.PauliZ(0)
Пример #9
0
 def circuit(w, x, y):
     qml.RX(x, [0])
     qml.RX(y, [1])
     return qml.expval.PauliZ(0), qml.expval.PauliZ(1)
Пример #10
0
 def qf(x):
     qml.RX(x, [0])
     qml.CNOT([0, 1])
     return qml.expval.PauliZ(0), qml.expval.PauliZ(
         1), qml.expval.PauliX(0)
Пример #11
0
 def qf(x):
     qml.RX(x, [0])
     qml.CNOT([0, 2])
     return qml.expval.PauliZ(0)
 def circuit(reused_param, other_param):
     qml.RX(extra_param, [0])
     qml.RY(reused_param, [0])
     qml.RZ(other_param, [0])
     qml.RX(reused_param, [0])
     return qml.expval.PauliZ(0)
 def circuit(x):
     qml.RX(x, [0])
     return qml.expval.PauliZ(0)
Пример #14
0
 def circuit(a, b):
     qml.RX(a[0], 0)
     qml.RX(a[1], 1)
     qml.RX(b[2, 1], 2)
     return qml.expval.PauliZ(0), qml.expval.PauliZ(
         1), qml.expval.PauliZ(2)
Пример #15
0
 def circuit(x, target_observable=None):
     qml.RX(x[0], wires=0)
     qml.RY(x[1], wires=0)
     qml.RZ(x[2], wires=0)
     qml.CNOT(wires=[0, 1])
     return qml.expval.Hermitian(target_observable, wires=[0, 1])
Пример #16
0
 def circuit(w, x=None):
     qml.RX(w, [0])
     qml.RX(x, [1])
     return qml.expval.PauliZ(0), qml.expval.PauliZ(1)
Пример #17
0
 def qf(x):
     qml.RX(x, wires=[0])
     qml.CNOT(wires=[0, 2])
     return qml.expval(qml.PauliZ(0))
Пример #18
0
 def qf(x):
     qml.RX(x, [0])
     return qml.expval.PauliZ(0), 0.3
Пример #19
0
 def circuit(reused_param, other_param):
     qml.RX(reused_param, wires=[0])
     qml.RZ(other_param, wires=[0])
     qml.RX(reused_param, wires=[0])
     return qml.expval(qml.PauliZ(0))
Пример #20
0
 def qf(x):
     qml.RX(x, [0])
     ex = qml.expval.PauliZ(1)
     return qml.expval.PauliZ(0), ex
Пример #21
0
 def circuit(x, y, input_state=np.array([0, 0])):
     qml.BasisState(input_state, wires=[0, 1])
     qml.RX(x, wires=[0])
     qml.RY(y, wires=[0])
     return qml.expval(qml.PauliZ(0))
Пример #22
0
 def qf(x):
     qml.RX(x, [0])
     ev = qml.expval.PauliZ(1)
     qml.RY(0.5, [0])
     return ev
Пример #23
0
 def qf(x):
     qml.RX(x, wires=[0])
     return qml.expval(qml.PauliZ(0)), 0.3
Пример #24
0
 def circuit(x):
     """Test quantum function"""
     qml.RX(x, wires=0)
     return qml.expval.Identity(0)
Пример #25
0
 def qf(x):
     qml.RX(x, wires=[0])
     ev = qml.expval(qml.PauliZ(1))
     qml.RY(0.5, wires=[0])
     return ev
Пример #26
0
 def circuit(x):
     """Test quantum function"""
     qml.RX(x, wires=0)
     return qml.expval.PauliY(0)
Пример #27
0
def quant_fun(variables):
    qml.RX(variables[0][1], wires=[0])
    qml.RY(variables[1][2], wires=[0])
    qml.RY(variables[2], wires=[0])
    return qml.expval.PauliZ(0)
Пример #28
0
 def circuit(*x):
     """Reference quantum function"""
     qml.RX(a, wires=0)
     return op(*x, wires=wires)
Пример #29
0
def quant_fun_flat(var):
    qml.RX(var[0], wires=[0])
    qml.RY(var[1], wires=[0])
    qml.RY(var[2], wires=[0])
    qml.RX(var[3], wires=[0])
    return qml.expval.PauliZ(0)
Пример #30
0
 def qf(x):
     qml.RX(x, [0])
     qml.CNOT([0, 1])
     qml.RY(0.4, [0])
     qml.RZ(-0.2, [1])
     return qml.expval.PauliX(0), qml.expval.PauliZ(1)