Example #1
0
    def test_noise_model_noise_instructions(self):
        """Test noise instructions"""
        model = NoiseModel()
        target = []
        self.assertEqual(model.noise_instructions, target)

        # Check a non-standard gate is added to noise instructions
        model = NoiseModel()
        model.add_all_qubit_quantum_error(reset_error(0.2), ['label'], False)
        target = ['label']
        self.assertEqual(model.noise_instructions, target)

        # Check a standard gate is added to noise instructions
        model = NoiseModel()
        model.add_all_qubit_quantum_error(reset_error(0.2), ['h'], False)
        target = ['h']
        self.assertEqual(model.noise_instructions, target)

        # Check a reset is added to noise instructions
        model = NoiseModel()
        model.add_all_qubit_quantum_error(reset_error(0.2), ['reset'], False)
        target = ['reset']
        self.assertEqual(model.noise_instructions, target)

        # Check a measure is added to noise instructions for readout error
        model = NoiseModel()
        model.add_all_qubit_readout_error([[0.9, 0.1], [0, 1]], False)
        target = ['measure']
        self.assertEqual(model.noise_instructions, target)
Example #2
0
    def test_noise_model_basis_gates(self):
        """Test noise model basis_gates"""
        basis_gates = ['u1', 'u2', 'u3', 'cx']
        model = NoiseModel(basis_gates)
        target = sorted(basis_gates)
        self.assertEqual(model.basis_gates, target)

        # Check adding readout errors doesn't add to basis gates
        model = NoiseModel(basis_gates)
        target = sorted(basis_gates)
        model.add_all_qubit_readout_error([[0.9, 0.1], [0, 1]], False)
        self.assertEqual(model.basis_gates, target)
        model.add_readout_error([[0.9, 0.1], [0, 1]], [2], False)
        self.assertEqual(model.basis_gates, target)

        # Check a reset instruction error isn't added to basis gates
        model = NoiseModel(basis_gates)
        target = sorted(basis_gates)
        model.add_all_qubit_quantum_error(reset_error(0.2), ['reset'], False)
        self.assertEqual(model.basis_gates, target)

        # Check a non-standard gate isn't added to basis gates
        model = NoiseModel(basis_gates)
        target = sorted(basis_gates)
        model.add_all_qubit_quantum_error(reset_error(0.2), ['label'], False)
        self.assertEqual(model.basis_gates, target)

        # Check a standard gate is added to basis gates
        model = NoiseModel(basis_gates)
        target = sorted(basis_gates + ['h'])
        model.add_all_qubit_quantum_error(reset_error(0.2), ['h'], False)
        self.assertEqual(model.basis_gates, target)
def reset_gate_error_noise_models():
    """Reset gate error noise models"""
    noise_models = []

    # 50% reset to 0 state on qubit 0
    error = reset_error(0.5)
    noise_model = NoiseModel()
    noise_model.add_quantum_error(error, 'x', [0])
    noise_models.append(noise_model)

    # 25% reset to 0 state on qubit 1
    error = reset_error(0.25)
    noise_model = NoiseModel()
    noise_model.add_quantum_error(error, 'x', [1])
    noise_models.append(noise_model)

    # 100% reset error to 0 on all qubits
    error = reset_error(1)
    noise_model = NoiseModel()
    noise_model.add_all_qubit_quantum_error(error, ['id', 'x'])
    noise_models.append(noise_model)

    # 100% reset error to 1 on all qubits
    error = reset_error(0, 1)
    noise_model = NoiseModel()
    noise_model.add_all_qubit_quantum_error(error, ['id', 'x'])
    noise_models.append(noise_model)

    # 25% reset error to 0 and 1 on all qubits
    error = reset_error(0.25, 0.25)
    noise_model = NoiseModel()
    noise_model.add_all_qubit_quantum_error(error, ['id', 'x'])
    noise_models.append(noise_model)

    return noise_models
 def test_standard_reset0reset1_error_50percent(self):
     """Test 100% Pauli error on id gates"""
     qr = QuantumRegister(2, 'qr')
     cr = ClassicalRegister(2, 'cr')
     circuit = QuantumCircuit(qr, cr)
     circuit.iden(qr[0])
     circuit.x(qr[1])
     circuit.barrier(qr)
     circuit.measure(qr, cr)
     backend = QasmSimulator()
     shots = 2000
     # test noise model
     error = reset_error(0.25, 0.25)
     noise_model = NoiseModel()
     noise_model.add_all_qubit_quantum_error(error, ['id', 'x'])
     # Execute
     target = {
         '0x0': 3 * shots / 16,
         '0x1': shots / 16,
         '0x2': 9 * shots / 16,
         '0x3': 3 * shots / 16
     }
     qobj = compile([circuit],
                    backend,
                    shots=shots,
                    basis_gates=noise_model.basis_gates)
     result = backend.run(qobj, noise_model=noise_model).result()
     self.is_completed(result)
     self.compare_counts(result, [circuit], [target], delta=0.05 * shots)
 def test_reset(self):
     # approximating amplitude damping using relaxation operators
     gamma = 0.23
     error = amplitude_damping_error(gamma)
     p = (gamma - numpy.sqrt(1 - gamma) + 1) / 2
     q = 0
     expected_results = reset_error(p, q)
     results = approximate_quantum_error(error, operator_string="reset")
     self.assertErrorsAlmostEqual(results, expected_results)
    def test_approx_noise_model(self):
        noise_model = NoiseModel()
        gamma = 0.23
        p = 0.4
        q = 0.33
        ad_error = amplitude_damping_error(gamma)
        r_error = reset_error(p, q)  # should be approximated as-is
        noise_model.add_all_qubit_quantum_error(ad_error, 'iden x y s')
        noise_model.add_all_qubit_quantum_error(r_error, 'iden z h')

        result = approximate_noise_model(noise_model, operator_string="reset")

        expected_result = NoiseModel()
        gamma_p = (gamma - numpy.sqrt(1 - gamma) + 1) / 2
        gamma_q = 0
        ad_error_approx = reset_error(gamma_p, gamma_q)
        expected_result.add_all_qubit_quantum_error(ad_error_approx,
                                                    'iden x y s')
        expected_result.add_all_qubit_quantum_error(r_error, 'iden z h')

        self.assertNoiseModelsAlmostEqual(expected_result, result)
Example #7
0
    def test_transform_noise(self):
        org_error = reset_error(0.2)
        new_error = pauli_error([("I", 0.5), ("Z", 0.5)])

        model = NoiseModel()
        model.add_all_qubit_quantum_error(org_error, ['x'])
        model.add_quantum_error(org_error, ['sx'], [0])
        model.add_all_qubit_readout_error([[0.9, 0.1], [0, 1]])

        def map_func(noise):
            return new_error if noise == org_error else None

        actual = transform_noise_model(model, map_func)

        expected = NoiseModel()
        expected.add_all_qubit_quantum_error(new_error, ['x'])
        expected.add_quantum_error(new_error, ['sx'], [0])
        expected.add_all_qubit_readout_error([[0.9, 0.1], [0, 1]])

        self.assertEqual(actual, expected)
Example #8
0
 def test_standard_reset1_error_100percent(self):
     """Test 100% Pauli error on id gates"""
     qr = QuantumRegister(1, 'qr')
     cr = ClassicalRegister(1, 'cr')
     circuit = QuantumCircuit(qr, cr)
     circuit.iden(qr)
     circuit.barrier(qr)
     circuit.measure(qr, cr)
     backend = QasmSimulator()
     shots = 100
     # test noise model
     error = reset_error(0, 1)
     noise_model = NoiseModel()
     noise_model.add_all_qubit_quantum_error(error, ['id', 'x'])
     # Execute
     target = {'0x1': shots}
     circuit = transpile(circuit, basis_gates=noise_model.basis_gates)
     qobj = assemble([circuit], backend, shots=shots)
     result = backend.run(qobj, noise_model=noise_model).result()
     self.is_completed(result)
     self.compare_counts(result, [circuit], [target], delta=0)