Exemplo n.º 1
0
 def qf(x, y):
     qml.Displacement(x, 0, [0])
     qml.CubicPhase(0.2, [0])  # nongaussian succeeding x
     qml.Squeezing(0.3, x,
                   [1])  # x affects gates on both wires, y unused
     qml.Rotation(1.3, [1])
     return qml.expval.X(0), qml.expval.X(1)
Exemplo n.º 2
0
 def qf(x, y):
     qml.Displacement(x, 0, [0])
     qml.CubicPhase(0.2, [0])
     qml.Squeezing(0.3, y, [1])
     qml.Rotation(1.3, [1])
     #qml.Kerr(0.4, [0])  # nongaussian succeeding x but not y   TODO when QNode uses a DAG to describe the circuit, uncomment this line
     return qml.expval.X(0), qml.expval.X(1)
Exemplo n.º 3
0
 def qf(x, y):
     qml.Displacement(x, 0, wires=[0])
     qml.Displacement(1.2, y, wires=[0])
     qml.Beamsplitter(0.2, 1.7, wires=[0, 1])
     qml.Rotation(1.9, wires=[0])
     qml.Kerr(0.3, wires=[1])  # nongaussian succeeding both x and y due to the beamsplitter
     return qml.expval(qml.X(0)), qml.expval(qml.X(1))
 def circuit(x):
     args = [0.3] * G.num_params
     args[0] = x
     qml.Displacement(0.5, 0, wires=0)
     G(*args, wires=range(G.num_wires))
     qml.Beamsplitter(1.3, -2.3, wires=[0, 1])
     qml.Displacement(-0.5, 0, wires=0)
     qml.Squeezing(0.5, -1.5, wires=0)
     qml.Rotation(-1.1, wires=0)
     return O(wires=0)
 def circuit(y):
     qml.Displacement(alpha, 0., wires=[0])
     qml.Rotation(y, wires=[0])
     return qml.expval.X(0)
 def circuit(x, y):
     qml.Displacement(x, 0, wires=[0])
     qml.Rotation(y, wires=[0])
     qml.Displacement(0, x, wires=[0])
     return qml.expval.X(0)
 def qf(x, y, z):
     qml.Displacement(x, 0.2, wires=[0])
     qml.Squeezing(y, z, wires=[0])
     qml.Rotation(-0.2, wires=[0])
     return qml.expval.X(0)
Exemplo n.º 8
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)
Exemplo n.º 9
0
 def circuit(r, phi):
     qml.Squeezing(r, 0, wires=0)
     qml.Rotation(phi, wires=0)
     return qml.var(qml.X(0))