Beispiel #1
0
    def test_validation_num_acquires(self):
        """Test that validation fails if 0 or >1 acquire is given in a schedule."""

        test_sim = PulseSimulator.from_backend(FakeArmonk())

        # check that too many acquires results in an error
        qobj = assemble([self._1Q_schedule(num_acquires=2)],
                        backend=test_sim,
                        meas_level=2,
                        qubit_lo_freq=[0.],
                        meas_return='single',
                        shots=256)

        try:
            test_sim.run(qobj, validate=True).result()
        except AerError as error:
            self.assertTrue('does not support multiple Acquire' in error.message)

        # check that no acquires results in an error
        qobj = assemble([self._1Q_schedule(num_acquires=0)],
                        backend=test_sim,
                        meas_level=2,
                        qubit_lo_freq=[0.],
                        meas_return='single',
                        shots=256)

        try:
            test_sim.run(qobj, validate=True).result()
        except AerError as error:
            self.assertTrue('requires at least one Acquire' in error.message)
Beispiel #2
0
    def test_set_system_model_from_backend(self):
        """Test setting system model when constructing from backend."""

        armonk_backend = FakeArmonk()
        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)]]

        armonk_sim = None

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

            armonk_sim = PulseSimulator.from_backend(backend=armonk_backend,
                                                     system_model=system_model)

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

        # check that system model properties have been imported
        self.assertEqual(armonk_sim.configuration().dt, system_model.dt)
        self.assertEqual(armonk_sim.configuration().u_channel_lo,
                         system_model.u_channel_lo)
Beispiel #3
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)
Beispiel #4
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)
# The pulse simulator
from qiskit.providers.aer import PulseSimulator

# Object for representing physical models
from qiskit.providers.aer.pulse import PulseSystemModel
from qiskit.providers.aer.pulse import duffing_system_model

# Mock Armonk backend
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]: