Ejemplo n.º 1
0
    def test_save_expval_var_cptp_pauli(self, pauli):
        """Test Pauli expval_var for stabilizer circuit"""

        SUPPORTED_METHODS = [
            'density_matrix', 'density_matrix_gpu', 'density_matrix_thrust'
        ]
        SEED = 5832

        opts = self.BACKEND_OPTS.copy()
        if opts.get('method') in SUPPORTED_METHODS:

            oper = qi.Pauli(pauli)

            # CPTP channel test circuit
            channel = qi.random_quantum_channel(4, seed=SEED)
            state_circ = QuantumCircuit(2)
            state_circ.append(channel, range(2))

            state = qi.DensityMatrix(state_circ)
            expval = state.expectation_value(oper).real
            variance = state.expectation_value(oper**2).real - expval**2
            target = [expval, variance]

            # Snapshot circuit
            circ = transpile(state_circ, self.SIMULATOR)
            circ.save_expectation_value_variance(oper, [0, 1], label='expval')
            qobj = assemble(circ)
            result = self.SIMULATOR.run(qobj, **opts).result()

            self.assertTrue(result.success)
            value = result.data(0)['expval']
            self.assertTrue(allclose(value, target))
Ejemplo n.º 2
0
 def test_roundtrip_quantum_channel(self, rep):
     """Test round-trip serialization of a DensityMatrix"""
     chan_cls = {
         "Choi": qi.Choi,
         "SuperOp": qi.SuperOp,
         "Kraus": qi.Kraus,
         "Stinespring": qi.Stinespring,
         "PTM": qi.PTM,
         "Chi": qi.Chi,
     }
     obj = chan_cls[rep](qi.random_quantum_channel(2, seed=10))
     self.assertRoundTripSerializable(obj)
Ejemplo n.º 3
0
 def test_save_expval_var_cptp_pauli(self, method, device, pauli):
     """Test Pauli expval_var for stabilizer circuit"""
     SEED = 5832
     oper = qi.Operator(qi.Operator(qi.Pauli(pauli)))
     channel = qi.random_quantum_channel(4, seed=SEED)
     circ = QuantumCircuit(2)
     circ.append(channel, range(2))
     qubits = [0, 1]
     self._test_save_expval(circ,
                            oper,
                            qubits,
                            True,
                            method=method,
                            device=device)
Ejemplo n.º 4
0
    def test_set_superop(self, method, device, num_qubits):
        """Test SetSuperOp instruction"""
        backend = self.backend(method=method, device=device)

        seed = 100
        label = 'state'

        target = qi.SuperOp(qi.random_quantum_channel(2**num_qubits,
                                                      seed=seed))

        circ = QuantumCircuit(num_qubits)
        circ.set_superop(target)
        circ.save_superop(label=label)

        # Run
        result = backend.run(transpile(circ, backend, optimization_level=0),
                             shots=1).result()
        self.assertTrue(result.success)
        simdata = result.data(0)
        self.assertIn(label, simdata)
        value = qi.SuperOp(simdata[label])
        self.assertEqual(value, target)
Ejemplo n.º 5
0
 def test_superop_linop(self):
     orig = qi.SuperOp(qi.random_quantum_channel(4, seed=10))
     compat = cqi.SuperOp(orig.data)
     self.assertEqual(2 * compat - orig, orig)
     self.assertEqual(2 * orig - compat, orig)
Ejemplo n.º 6
0
 def test_superop_eq(self):
     orig = qi.SuperOp(qi.random_quantum_channel(4, seed=10))
     compat = cqi.SuperOp(orig.data)
     self.assertEqual(compat, orig)
     self.assertEqual(orig, compat)