コード例 #1
0
def rand_pulse_sequence(d: int,
                        n_dt: int,
                        n_cops: int = 3,
                        n_nops: int = 3,
                        btype: str = 'GGM',
                        seed=None):
    """Random pulse sequence instance"""
    if seed is not None:
        rng.seed(seed)

    c_opers = rand_herm_traceless(d, n_cops)
    n_opers = rand_herm_traceless(d, n_nops)

    c_coeffs = rng.standard_normal((n_cops, n_dt))
    n_coeffs = rng.random_sample((n_nops, n_dt))

    letters = np.array(list(string.ascii_letters))
    c_identifiers = rng.choice(letters, n_cops, replace=False)
    n_identifiers = rng.choice(letters, n_nops, replace=False)

    dt = 1 - rng.random_sample(n_dt)  # (0, 1] instead of [0, 1)
    if btype == 'GGM':
        basis = Basis.ggm(d)
    else:
        basis = Basis.pauli(int(np.log2(d)))

    pulse = PulseSequence(list(zip(c_opers, c_coeffs, c_identifiers)),
                          list(zip(n_opers, n_coeffs, n_identifiers)), dt,
                          basis)
    return pulse
コード例 #2
0
ファイル: test_util.py プロジェクト: qutech/filter_functions
    def test_get_indices_from_identifiers(self):
        pulse = PulseSequence(
            [[util.paulis[3], [2], 'Z'], [util.paulis[1], [1], 'X']],
            [[util.paulis[2], [2]]], [1])
        idx = util.get_indices_from_identifiers(pulse.c_oper_identifiers,
                                                ['X'])
        self.assertArrayEqual(idx, [0])

        idx = util.get_indices_from_identifiers(pulse.c_oper_identifiers, 'X')
        self.assertArrayEqual(idx, [0])

        idx = util.get_indices_from_identifiers(pulse.c_oper_identifiers,
                                                ['Z', 'X'])
        self.assertArrayEqual(idx, [1, 0])

        idx = util.get_indices_from_identifiers(pulse.c_oper_identifiers, None)
        self.assertArrayEqual(idx, [0, 1])

        idx = util.get_indices_from_identifiers(pulse.n_oper_identifiers,
                                                ['B_0'])
        self.assertArrayEqual(idx, [0])

        idx = util.get_indices_from_identifiers(pulse.n_oper_identifiers,
                                                'B_0')
        self.assertArrayEqual(idx, [0])

        with self.assertRaises(ValueError):
            util.get_indices_from_identifiers(pulse.n_oper_identifiers,
                                              ['foobar'])
コード例 #3
0
ファイル: test_util.py プロジェクト: JDTeske/filter_functions
    def test_get_sample_frequencies(self):
        pulse = PulseSequence([[util.paulis[1], [np.pi / 2]]],
                              [[util.paulis[1], [1]]],
                              [abs(rng.standard_normal())])
        # Default args
        omega = util.get_sample_frequencies(pulse)
        self.assertAlmostEqual(omega[0], 2e-2 * np.pi / pulse.tau)
        self.assertAlmostEqual(omega[-1], 2e2 * np.pi / pulse.tau)
        self.assertEqual(len(omega), 300)
        self.assertTrue((omega >= 0).all())
        self.assertLessEqual(np.var(np.diff(np.log(omega[150:]))), 1e-16)

        # custom args
        omega = util.get_sample_frequencies(pulse,
                                            spacing='linear',
                                            n_samples=50,
                                            include_quasistatic=True)
        self.assertAlmostEqual(omega[0], 0)
        self.assertAlmostEqual(omega[-1], 2e2 * np.pi / pulse.tau)
        self.assertEqual(len(omega), 50)
        self.assertTrue((omega >= 0).all())
        self.assertLessEqual(np.var(np.diff(omega[1:])), 1e-16)

        # Exceptions
        with self.assertRaises(ValueError):
            omega = util.get_sample_frequencies(pulse, spacing='foo')
コード例 #4
0
def state_infidelity(pulse: PulseSequence,
                     S: ndarray,
                     omega: ndarray,
                     ind: int = 2) -> float:
    """Compute state infidelity for input state eigenstate of pauli *ind*"""
    R = pulse.get_control_matrix(omega)
    F = np.einsum('jko->jo', util.abs2(R[:, np.delete([0, 1, 2], ind)]))
    return np.trapz(F * S, omega) / (2 * np.pi * pulse.d)
コード例 #5
0
    def test_symmetrize_spectrum(self):
        pulse = PulseSequence(
            [[util.paulis[1], [np.pi/2]]],
            [[util.paulis[1], [1]]],
            [abs(rng.standard_normal())]
        )

        asym_omega = util.get_sample_frequencies(pulse, symmetric=False,
                                                 n_samples=100)
        sym_omega = util.get_sample_frequencies(pulse, symmetric=True,
                                                n_samples=200)

        S_symmetrized, omega_symmetrized = util.symmetrize_spectrum(
            1/asym_omega**0.7, asym_omega)
        self.assertArrayEqual(omega_symmetrized, sym_omega)
        self.assertArrayEqual(S_symmetrized[99::-1], S_symmetrized[100:])
        self.assertArrayEqual(S_symmetrized[100:]*2, 1/asym_omega**0.7)

        # zero frequency not doubled
        omega = np.arange(10)
        S_sym, omega_sym = util.symmetrize_spectrum(omega, omega)
        self.assertArrayEqual(S_sym, np.abs(np.arange(-9, 10)/2))
        self.assertArrayEqual(omega_sym, np.arange(-9, 10))