예제 #1
0
 def qf(x, y):
     qml.Displacement(x, 0, wires=[0])
     qml.CubicPhase(0.2, wires=[0])  # nongaussian succeeding x
     qml.Squeezing(0.3, x,
                   wires=[1])  # x affects gates on both wires, y unused
     qml.Rotation(1.3, wires=[1])
     return qml.expval(qml.X(0)), qml.expval(qml.X(1))
예제 #2
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))
예제 #3
0
 def qf(x, y):
     qml.Displacement(x, 0, wires=[0])
     qml.CubicPhase(0.2, wires=[0])
     qml.Squeezing(0.3, y, wires=[1])
     qml.Rotation(1.3, wires=[1])
     # nongaussian succeeding x but not y
     # TODO when QNode uses a DAG to describe the circuit, uncomment this line
     #qml.Kerr(0.4, [0])
     return qml.expval(qml.X(0)), qml.expval(qml.X(1))
예제 #4
0
                def circuit(x):
                    qml.Displacement(x, 0, wires=0)

                    if cls.par_domain == 'A':
                        cls(U, wires=w)
                    else:
                        cls(wires=w)
                    return qml.expval(qml.X(0))
예제 #5
0
            def circuit(*x):
                """Test quantum function"""
                x = prep_par(x, op)
                op(*x, wires=wires)

                if issubclass(op, qml.operation.CV):
                    return qml.expval(qml.X(0))

                return qml.expval(qml.PauliZ(0))
예제 #6
0
    def test_execute(self):
        """check that execution works on supported operations/observables"""
        self.logTestName()

        for dev in self.dev.values():
            ops = dev.operations
            exps = dev.observables

            queue = []
            for o in ops:
                log.debug('Queueing gate %s...', o)
                op = qml.ops.__getattribute__(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.append(
                    op(*params,
                       wires=list(range(op.num_wires)),
                       do_queue=False))

            temp = [isinstance(op, qml.operation.CV) for op in queue]
            if all(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))])

            self.assertTrue(isinstance(expval, np.ndarray))
예제 #7
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(qml.X(0))
예제 #8
0
 def qf(x):
     return qml.expval(qml.X(0))
예제 #9
0
 def qf(x):
     qml.Displacement(0.5, 0, wires=[0])
     return qml.expval(qml.X(0))
예제 #10
0
 def circuit(r, phi):
     qml.Displacement(r, phi, wires=[0])
     return qml.expval(qml.X(0))
예제 #11
0
 def circuit(y):
     qml.Displacement(alpha, 0., wires=[0])
     qml.Beamsplitter(y, 0, wires=[0, 1])
     return qml.expval(qml.X(0))
예제 #12
0
 def circuit(y):
     qml.Displacement(alpha, 0., wires=[0])
     qml.Rotation(y, wires=[0])
     return qml.expval(qml.X(0))
예제 #13
0
 def circuit(*x):
     """Reference quantum function"""
     qml.Displacement(a, 0, wires=[0])
     op(*x, wires=wires)
     return qml.expval(qml.X(0))
예제 #14
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(qml.X(0))
예제 #15
0
 def circuit(x):
     """Test quantum function"""
     qml.Displacement(x, 0, wires=0)
     return qml.expval(qml.X(0))
예제 #16
0
 def circuit(y, r=0.5):
     qml.Displacement(r, 0., wires=[0])
     qml.Squeezing(y, 0., wires=[0])
     return qml.expval(qml.X(0))
예제 #17
0
 def qf(x, y):
     qml.Kerr(y, wires=[1])
     qml.Displacement(x, 0, wires=[0])
     qml.Beamsplitter(0.2, 1.7, wires=[0, 1])
     return qml.expval(qml.X(0)), qml.expval(qml.X(1))
예제 #18
0
 def circuit(r, phi):
     qml.Squeezing(r, 0, wires=0)
     qml.Rotation(phi, wires=0)
     return qml.var(qml.X(0))
예제 #19
0
 def qf(x):
     return qml.expval(qml.X(wires=0))
예제 #20
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)
예제 #21
0
 def qf(x, y):
     qml.Displacement(x, 0, wires=[0])
     qml.Squeezing(y, -1.3*y, wires=[0])
     return qml.expval(qml.X(0))