Ejemplo n.º 1
0
 def test_depolarizing_error_ideal(self):
     """Test depolarizing error with p=0 (ideal) as gate qobj"""
     # 1 qubit
     error = depolarizing_error(0, 1)
     _, p = error.error_term(0)
     self.assertEqual(p, 1, msg="ideal probability")
     self.assertTrue(error.ideal(), msg="ideal circuit")
     # 2-qubit
     error = depolarizing_error(0, 2)
     _, p = error.error_term(0)
     self.assertEqual(p, 1, msg="ideal probability")
     self.assertTrue(error.ideal(), msg="ideal circuit")
def create_depolarizing_noise_model():
    """
    create noise model of depolarizing error

    Returns:
        NoiseModel: depolarizing error noise model

    """
    noise_model = NoiseModel()
    p1q = 0.002
    p2q = 0.01
    noise_model.add_all_qubit_quantum_error(depolarizing_error(p1q, 1), 'u2')
    noise_model.add_all_qubit_quantum_error(depolarizing_error(2 * p1q, 1), 'u3')
    noise_model.add_all_qubit_quantum_error(depolarizing_error(p2q, 2), 'cx')
    return noise_model
Ejemplo n.º 3
0
 def test_depolarizing_error_2q_gate(self):
     """Test 2-qubit depolarizing error as gate qobj"""
     p_depol = 0.3
     with self.assertWarns(DeprecationWarning):
         actual = depolarizing_error(p_depol, 2, standard_gates=True)
     target_circs = [[{"name": "id", "qubits": [0]}, {"name": "id", "qubits": [1]}],
                     [{"name": "id", "qubits": [0]}, {"name": "x", "qubits": [1]}],
                     [{"name": "id", "qubits": [0]}, {"name": "y", "qubits": [1]}],
                     [{"name": "id", "qubits": [0]}, {"name": "z", "qubits": [1]}],
                     [{"name": "x", "qubits": [0]}, {"name": "id", "qubits": [1]}],
                     [{"name": "x", "qubits": [0]}, {"name": "x", "qubits": [1]}],
                     [{"name": "x", "qubits": [0]}, {"name": "y", "qubits": [1]}],
                     [{"name": "x", "qubits": [0]}, {"name": "z", "qubits": [1]}],
                     [{"name": "y", "qubits": [0]}, {"name": "id", "qubits": [1]}],
                     [{"name": "y", "qubits": [0]}, {"name": "x", "qubits": [1]}],
                     [{"name": "y", "qubits": [0]}, {"name": "y", "qubits": [1]}],
                     [{"name": "y", "qubits": [0]}, {"name": "z", "qubits": [1]}],
                     [{"name": "z", "qubits": [0]}, {"name": "id", "qubits": [1]}],
                     [{"name": "z", "qubits": [0]}, {"name": "x", "qubits": [1]}],
                     [{"name": "z", "qubits": [0]}, {"name": "y", "qubits": [1]}],
                     [{"name": "z", "qubits": [0]}, {"name": "z", "qubits": [1]}]]
     target_probs = [1 - p_depol * 15 / 16] + [p_depol / 16] * 15
     with self.assertWarns(DeprecationWarning):
         expected = QuantumError(zip(target_circs, target_probs), standard_gates=True)
     for i in range(actual.size):
         circ, prob = actual.error_term(i)
         expected_circ, expected_prob = expected.error_term(i)
         self.assertEqual(circ, expected_circ, msg=f"Incorrect {i}-th circuit")
         self.assertAlmostEqual(prob, expected_prob, msg=f"Incorrect {i}-th probability")
Ejemplo n.º 4
0
    def test_depolarizing_error_2q_gate(self):
        """Test 2-qubit depolarizing error as gate qobj"""
        p_depol = 0.3
        actual = depolarizing_error(p_depol, 2)

        expected = QuantumError([
            (PauliGate("II"), 1 - p_depol * 15 / 16),
            (PauliGate("IX"), p_depol / 16),
            (PauliGate("IY"), p_depol / 16),
            (PauliGate("IZ"), p_depol / 16),
            (PauliGate("XI"), p_depol / 16),
            (PauliGate("XX"), p_depol / 16),
            (PauliGate("XY"), p_depol / 16),
            (PauliGate("XZ"), p_depol / 16),
            (PauliGate("YI"), p_depol / 16),
            (PauliGate("YX"), p_depol / 16),
            (PauliGate("YY"), p_depol / 16),
            (PauliGate("YZ"), p_depol / 16),
            (PauliGate("ZI"), p_depol / 16),
            (PauliGate("ZX"), p_depol / 16),
            (PauliGate("ZY"), p_depol / 16),
            (PauliGate("ZZ"), p_depol / 16),
        ])
        for i in range(actual.size):
            circ, prob = actual.error_term(i)
            expected_circ, expected_prob = expected.error_term(i)
            self.assertEqual(circ, expected_circ, msg=f"Incorrect {i}-th circuit")
            self.assertAlmostEqual(prob, expected_prob, msg=f"Incorrect {i}-th probability")
Ejemplo n.º 5
0
    def test_depolarizing_error_1q_gate(self):
        """Test 1-qubit depolarizing error as gate qobj"""
        p_depol = 0.3
        actual = depolarizing_error(p_depol, 1)

        expected = QuantumError([
            (IGate(), 1 - p_depol*3/4),
            (XGate(), p_depol/4),
            (YGate(), p_depol/4),
            (ZGate(), p_depol/4)
        ])
        for i in range(actual.size):
            circ, prob = actual.error_term(i)
            expected_circ, expected_prob = expected.error_term(i)
            self.assertEqual(circ, expected_circ, msg=f"Incorrect {i}-th circuit")
            self.assertAlmostEqual(prob, expected_prob, msg=f"Incorrect {i}-th probability")
#______________________________________________________________________________________

# The Unitary is an identity (with a global phase)
backend = qiskit.Aer.get_backend('unitary_simulator')
basis_gates = ['u1', 'u2', 'u3', 'cx']  # use U,CX for now
job = qiskit.execute(qc, backend=backend, basis_gates=basis_gates)
print(np.around(job.result().get_unitary(), 3))

#______________________________________________________________________________________

# Run on a noisy simulator
noise_model = NoiseModel()
# Depolarizing_error
dp = 0.005
noise_model.add_all_qubit_quantum_error(depolarizing_error(dp, 1),
                                        ['u1', 'u2', 'u3'])
noise_model.add_all_qubit_quantum_error(depolarizing_error(2 * dp, 2), 'cx')

backend = qiskit.Aer.get_backend('qasm_simulator')
#______________________________________________________________________________________

# Create the RB fitter
backend = qiskit.Aer.get_backend('qasm_simulator')
basis_gates = ['u1', 'u2', 'u3', 'cx']
shots = 200
qobj_list = []
rb_fit = rb.RBFitter(None, xdata, rb_opts['rb_pattern'])
for rb_seed, rb_circ_seed in enumerate(rb_circs):
    print('Compiling seed %d' % rb_seed)
    new_rb_circ_seed = qiskit.compiler.transpile(rb_circ_seed,
Ejemplo n.º 7
0
	
#______________________________________________________________________________________

# The Unitary is an identity (with a global phase)
backend = qiskit.Aer.get_backend('unitary_simulator')
basis_gates = ['u1','u2','u3','cx'] # use U,CX for now
job = qiskit.execute(qc, backend=backend, basis_gates=basis_gates)
print(np.around(job.result().get_unitary(),3))

#______________________________________________________________________________________

# Run on a noisy simulator
noise_model = NoiseModel()
# Depolarizing_error
dp = 0.005 
noise_model.add_all_qubit_quantum_error(depolarizing_error(dp, 1), ['u1', 'u2', 'u3'])
noise_model.add_all_qubit_quantum_error(depolarizing_error(2*dp, 2), 'cx')

backend = qiskit.Aer.get_backend('qasm_simulator')
#______________________________________________________________________________________

# Create the RB fitter
backend = qiskit.Aer.get_backend('qasm_simulator')
basis_gates = ['u1','u2','u3','cx'] 
shots = 200
qobj_list = []
rb_fit = rb.RBFitter(None, xdata, rb_opts['rb_pattern'])
for rb_seed,rb_circ_seed in enumerate(rb_circs):
    print('Compiling seed %d'%rb_seed)
    new_rb_circ_seed = qiskit.compiler.transpile(rb_circ_seed, basis_gates=basis_gates)
    qobj = qiskit.compiler.assemble(new_rb_circ_seed, shots=shots)
Ejemplo n.º 8
0
from qiskit.providers.aer.noise import NoiseModel
from qiskit.providers.aer.noise.errors.standard_errors import depolarizing_error

# Import the RB Functions
from qiskit.ignis.verification.randomized_benchmarking import randomized_benchmarking_seq, RBFitter

# Generate RB circuits (2Q RB)
rb_opts = {}
rb_opts['length_vector'] = [1, 10, 20, 50, 75, 100, 125]
rb_opts['nseeds'] = 5
rb_opts['rb_pattern'] = [[0, 1]]
rb_circs, xdata = randomized_benchmarking_seq(**rb_opts)

# Run on a noisy simulator
noise_model = NoiseModel()
noise_model.add_all_qubit_quantum_error(depolarizing_error(0.002, 1),
                                        ['u1', 'u2', 'u3'])
noise_model.add_all_qubit_quantum_error(depolarizing_error(0.002, 2), 'cx')

backend = qiskit.Aer.get_backend('qasm_simulator')

# Create the RB fitter
rb_fit = RBFitter(None, xdata, rb_opts['rb_pattern'])
for rb_seed, rb_circ_seed in enumerate(rb_circs):

    job = qiskit.execute(rb_circ_seed,
                         backend=backend,
                         basis_gates=['u1', 'u2', 'u3', 'cx'],
                         noise_model=noise_model)

    # Add data to the fitter