コード例 #1
0
ファイル: test_api.py プロジェクト: jasonelhaderi/pypsqueak
    def test_mul_with_qOp_preserves_first_qOp_noise_model(self):
        '''
        Checks that after multiplication, the resulting `qOp` has
        the same noise model as the first operand.
        '''
        op1 = qOp(kraus_ops=damping_map(0.3))
        op2 = qOp()

        np.testing.assert_array_equal((op1 * op2)._qOp__noise_model,
                                      damping_map(0.3))
        self.assertEqual((op2 * op1)._qOp__noise_model, None)
コード例 #2
0
ファイル: test_api.py プロジェクト: jasonelhaderi/pypsqueak
    def test_set_noise_model(self):
        '''
        Verifies that setting a noise model succeeds.
        '''

        self.test_op.set_noise_model(damping_map(0.2))
        some_op = qOp(np.eye(2), damping_map(0.2))
        list_of_kraus_ops = [
            np.array([[1, 0], [0, np.sqrt(0.8)]]),
            np.array([[0, np.sqrt(0.2)], [0, 0]]),
        ]

        np.testing.assert_array_equal(
            some_op._qOp__noise_model.getKrausOperators(), list_of_kraus_ops)
        np.testing.assert_array_equal(
            self.test_op._qOp__noise_model.getKrausOperators(),
            list_of_kraus_ops)
コード例 #3
0
ファイル: test_api.py プロジェクト: jasonelhaderi/pypsqueak
    def test_qOpSizeMismatchWithNoiseModel(self):
        '''
        An exception gets thrown if the dimensions of the Kraus operators don't
        match the dimensions of the ``qOp`` when calling
        ``qOp.set_noise_model()``.
        '''

        twoQubitOperator = qOp().kron(qOp())

        self.assertRaises(WrongShapeError, twoQubitOperator.set_noise_model,
                          damping_map(0.5))
コード例 #4
0
ファイル: test_api.py プロジェクト: jasonelhaderi/pypsqueak
    def test_apply_noisy_gate_with_raised_register(self):
        '''
        Deterministic verification of application of gate with
        some NoiseModel set (using prob 1 amplitude damping) where
        qReg needs to be raised.
        '''

        singleQubitInOneStateInitialy = qReg()
        X.on(singleQubitInOneStateInitialy)

        self.test_op.set_noise_model(damping_map(1.0))
        self.test_op.on(singleQubitInOneStateInitialy, 1)

        np.testing.assert_array_equal(
            singleQubitInOneStateInitialy.dump_state(), [0, 1, 0, 0])
コード例 #5
0
ファイル: test_api.py プロジェクト: jasonelhaderi/pypsqueak
    def test_apply_noisy_gate(self):
        '''
        Deterministic verification of application of gate with
        some NoiseModel set (using prob 1 amplitude damping).
        '''

        registerInZeroStateInitially = qReg()
        registerInOneStateInitially = qReg()
        X.on(registerInOneStateInitially)

        self.test_op.set_noise_model(damping_map(1.0))
        self.test_op.on(registerInZeroStateInitially)
        self.test_op.on(registerInOneStateInitially)

        np.testing.assert_array_equal(
            registerInZeroStateInitially.dump_state(), [1, 0])
        np.testing.assert_array_equal(registerInOneStateInitially.dump_state(),
                                      [1, 0])
コード例 #6
0
# Prep a qReg in the |1> state
qubit = qReg()
X.on(qubit)

# Send it through an amp decay channel with 0.3 chance of decay.
if len(sys.argv) > 1 and int(sys.argv[1]) > 0:
    n_runs = int(sys.argv[1])
else:
    n_runs = 1000

if len(sys.argv) > 2 and float(sys.argv[2]) >= 0 and float(sys.argv[2]) <= 1:
    prob = float(sys.argv[2])
else:
    prob = 0.3
noisy_channel = qOp(kraus_ops=damping_map(prob))

zeros = 0
ones = 0

print("Sending the state |1> through a noisy channel {} times with amplitude decay probability={}...".format(n_runs, prob))
for i in range(n_runs):
    noisy_channel.on(qubit)
    result = qubit.measure(0)
    if result == 0:
        zeros += 1
        # Reset qReg to |1> for next run.
        X.on(qubit)
    else:
        # No need to reset qReg
        ones += 1