Пример #1
0
    def test_run_simulation_from_backend(self):
        """Construct from a backend and run a simulation."""
        armonk_backend = FakeArmonk()

        # manually override parameters to insulate from future changes to FakeArmonk
        freq_est = 4.97e9
        drive_est = 6.35e7
        armonk_backend.defaults().qubit_freq_est = [freq_est]
        armonk_backend.configuration().hamiltonian['h_str'] = [
            'wq0*0.5*(I0-Z0)', 'omegad0*X0||D0'
        ]
        armonk_backend.configuration().hamiltonian['vars'] = {
            'wq0': 2 * np.pi * freq_est,
            'omegad0': drive_est
        }
        armonk_backend.configuration().hamiltonian['qub'] = {'0': 2}
        dt = 2.2222222222222221e-10
        armonk_backend.configuration().dt = dt

        armonk_sim = PulseSimulator.from_backend(armonk_backend)
        armonk_sim.set_options(meas_level=2, meas_return='single', shots=1)

        total_samples = 250
        amp = np.pi / (drive_est * dt * total_samples)

        sched = self._1Q_schedule(total_samples, amp)
        # run and verify that a pi pulse had been done
        result = armonk_sim.run(sched).result()
        final_vec = result.get_statevector()
        probabilities = np.abs(final_vec)**2
        self.assertTrue(probabilities[0] < 1e-5)
        self.assertTrue(probabilities[1] > 1 - 1e-5)
Пример #2
0
    def test_set_system_model_after_construction(self):
        """Test setting the system model after construction."""

        system_model = self._system_model_1Q()

        # these are 1q systems so this doesn't make sense but can still be used to test
        system_model.u_channel_lo = [[UchannelLO(0, 1.0 + 0.0j)]]

        # first test setting after construction with no hamiltonian
        test_sim = PulseSimulator()

        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")

            test_sim.set_options(system_model=system_model)
            self.assertEqual(len(w), 0)

        # check that system model properties have been imported
        self.assertEqual(test_sim._system_model, system_model)
        self.assertEqual(test_sim.configuration().dt, system_model.dt)
        self.assertEqual(test_sim.configuration().u_channel_lo,
                         system_model.u_channel_lo)

        # next, construct a pulse simulator with a config containing a Hamiltonian and observe
        # warnings
        armonk_backend = FakeArmonk()
        test_sim = PulseSimulator(configuration=armonk_backend.configuration())

        # add system model and verify warning is raised
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")

            armonk_sim = test_sim.set_options(system_model=system_model)

            self.assertEqual(len(w), 1)
            self.assertTrue('inconsistencies' in str(w[-1].message))

        self.assertEqual(test_sim.configuration().dt, system_model.dt)
        self.assertEqual(test_sim.configuration().u_channel_lo,
                         system_model.u_channel_lo)
from qiskit.test.mock.backends.armonk.fake_armonk import FakeArmonk


# In[191]:


armonk_backend = FakeArmonk()


# In[192]:


freq_est = 4.97e9
drive_est = 6.35e7
armonk_backend.defaults().qubit_freq_est = [freq_est]
armonk_backend.configuration().hamiltonian['h_str']= ['wq0*0.5*(I0-Z0)', 'omegad0*X0||D0']
armonk_backend.configuration().hamiltonian['vars'] = {'wq0': 2 * np.pi * freq_est, 'omegad0': drive_est}
armonk_backend.configuration().hamiltonian['qub'] = {'0': 2}
armonk_backend.configuration().dt = 2.2222222222222221e-10


# In[200]:


dim_oscillators = 3

# single oscillator drift parameters
oscillator_freqs = [5.0e9, 5.1e9, 5.2e9]
anharm_freqs = [-0.33e9, -0.33e9, -0.33e9]

# drive strengths