예제 #1
0
    def benchmark(self, n=10):
        # Set seed to make iqp circuits deterministic
        random.seed(135)

        # n is the number of layers in the circuit
        if self.verbose:
            print("circuit: {} IQP gates, {} wires".format(
                n * self.n_wires, self.n_wires))

        def circuit():
            """Mutable IQP quantum circuit."""
            for i in range(self.n_wires):
                qml.Hadamard(i)

            for i in range(n * self.n_wires):
                wires = random_iqp_wires(self.n_wires)
                if len(wires) == 1:
                    qml.PauliZ(wires=wires)
                elif len(wires) == 2:
                    qml.CZ(wires=wires)
                elif len(wires) == 3:
                    CCZ(wires)

            for i in range(self.n_wires):
                qml.Hadamard(i)

            return meas_function(0)

        qnode = bu.create_qnode(circuit, self.device, mutable=True)
        qnode()

        return True
    def benchmark(self, n=10):
        # n is the number of parametrized layers in the circuit
        if self.verbose:
            print("circuit: {} parameters, {} wires".format(
                n * self.n_wires, self.n_wires))

        params = [
            qml.numpy.array(self.random_angles, copy=True, requires_grad=True)
            for _ in range(n)
        ]

        def circuit(params):
            """Parametrized circuit."""
            for _layer in range(n):
                qml.broadcast(qml.CNOT, pattern="double", wires=self.all_wires)
            for layer in range(n):
                qml.broadcast(qml.RX,
                              pattern="single",
                              wires=self.all_wires,
                              parameters=params[layer])
            return [bu.expval(qml.PauliZ(w)) for w in self.all_wires]

        qnode = bu.create_qnode(circuit,
                                self.device,
                                mutable=True,
                                qnode_type=self.qnode_type)
        qnode.jacobian([params])

        return True
예제 #3
0
    def benchmark(self, n=10):
        # Set seed to make iqp circuits deterministic
        random.seed(135)

        # n is the number of layers in the circuit
        if self.verbose:
            print("circuit: {} IQP gates, {} wires".format(n * self.n_wires, self.n_wires))

        qnode = bu.create_qnode(circuit, self.device, mutable=True)
        qnode(n=n, n_wires=self.n_wires)

        return True
예제 #4
0
    def benchmark(self, n=3):
        # n is the number of layers in the circuit
        if self.verbose:
            print("circuit: {} layers, {} wires".format(n, self.n_wires))

        features = np.arange(self.n_wires)
        init_weights = strong_ent_layers_uniform(n_layers=n,
                                                 n_wires=self.n_wires)

        qnode = bu.create_qnode(circuit, self.device, mutable=True)
        qnode(init_weights, features=features)
        qnode.jacobian((init_weights, ), {"features": features})
        return True
    def benchmark(self, n=10):
        # n is the number of layers in the circuit
        if self.verbose:
            print("circuit: {} parameters, {} wires".format(
                n * self.n_wires, self.n_wires))

        params1 = [
            qml.numpy.array(self.params1, copy=True, requires_grad=True)
            for _ in range(n)
        ]
        params2 = [
            qml.numpy.array(self.params2, copy=True, requires_grad=True)
            for _ in range(n)
        ]

        def circuit(params1, params2):
            """Parametrized circuit with nearest-neighbour gates."""
            for layer in range(n):
                qml.broadcast(
                    qml.RX,
                    pattern="single",
                    wires=self.all_wires,
                    parameters=params1[layer],
                )
                qml.broadcast(
                    qml.CRY,
                    pattern="chain",
                    wires=self.all_wires,
                    parameters=params2[layer],
                )
            return bu.expval(qml.PauliZ(0))

        qnode = bu.create_qnode(circuit,
                                self.device,
                                mutable=True,
                                qnode_type=self.qnode_type)
        qnode(params1, params2)

        return True
예제 #6
0
 def setup(self):
     self.qnode = bu.create_qnode(circuit, self.device, mutable=True)
 def setup(self):
     self.qnode = bu.create_qnode(circuit,
                                  self.device,
                                  mutable=True,
                                  interface=None)