def test_from_backend(self):
        """Test that configuration, defaults, and properties are correclty imported."""

        athens_backend = FakeAthens()
        athens_sim = PulseSimulator.from_backend(athens_backend)

        self.assertEqual(athens_backend.properties(), athens_sim.properties())
        # check that configuration is correctly imported
        backend_dict = athens_backend.configuration().to_dict()
        sim_dict = athens_sim.configuration().to_dict()
        for key in sim_dict:
            if key == 'backend_name':
                self.assertEqual(sim_dict[key], 'pulse_simulator(fake_athens)')
            elif key == 'description':
                desc = 'A Pulse-based simulator configured from the backend: fake_athens'
                self.assertEqual(sim_dict[key], desc)
            elif key == 'simulator':
                self.assertTrue(sim_dict[key], True)
            else:
                self.assertEqual(sim_dict[key], backend_dict[key])

        backend_dict = athens_backend.defaults().to_dict()
        sim_dict = athens_sim.defaults().to_dict()
        for key in sim_dict:
            if key == 'pulse_library':
                # need to compare pulse libraries directly due to containing dictionaries
                for idx, entry in enumerate(sim_dict[key]):
                    for entry_key in entry:
                        if entry_key == 'samples':
                            self.assertTrue(np.array_equal(entry[entry_key], backend_dict[key][idx][entry_key]))
                        else:
                            self.assertTrue(entry[entry_key] == backend_dict[key][idx][entry_key])
            else:
                self.assertEqual(sim_dict[key], backend_dict[key])
Example #2
0
    def test_from_backend_system_model(self):
        """Test that the system model is correctly imported from the backend."""

        athens_backend = FakeAthens()
        athens_sim = PulseSimulator.from_backend(athens_backend)

        # u channel lo
        athens_attr = athens_backend.configuration().u_channel_lo
        sim_attr = athens_sim.configuration().u_channel_lo
        model_attr = athens_sim._system_model.u_channel_lo
        self.assertTrue(sim_attr == athens_attr and model_attr == athens_attr)

        # dt
        athens_attr = athens_backend.configuration().dt
        sim_attr = athens_sim.configuration().dt
        model_attr = athens_sim._system_model.dt
        self.assertTrue(sim_attr == athens_attr and model_attr == athens_attr)
Example #3
0
    def test_parametric_pulses_error(self):
        """Verify error is raised if a parametric pulse makes it into the digest."""

        fake_backend = FakeAthens()
        backend = PulseSimulator.from_backend(fake_backend)

        # reset parametric_pulses option
        backend.set_option('parametric_pulses', fake_backend.configuration().parametric_pulses)

        qc = QuantumCircuit(2)
        qc.x(0)
        qc.h(1)
        qc.measure_all()
        sched = schedule(transpile(qc, backend), backend)

        with self.assertRaises(AerError):
            res = backend.run(sched).result()
Example #4
0
    def test_from_backend_parametric_pulses(self):
        """Verify that the parametric_pulses parameter is overriden in the PulseSimulator.
        Results don't matter, just need to check that it runs.
        """

        backend = PulseSimulator.from_backend(FakeAthens())

        qc = QuantumCircuit(2)
        qc.x(0)
        qc.h(1)
        qc.measure_all()

        sched = schedule(transpile(qc, backend), backend)
        res = backend.run(sched).result()
Example #5
0
    def test_set_system_model_options(self):
        """Test setting of options that need to be changed in multiple places."""

        athens_backend = FakeAthens()
        athens_sim = PulseSimulator.from_backend(athens_backend)

        # u channel lo
        set_attr = [[UchannelLO(0, 1.0 + 0.0j)]]
        athens_sim.set_options(u_channel_lo=set_attr)
        sim_attr = athens_sim.configuration().u_channel_lo
        model_attr = athens_sim._system_model.u_channel_lo
        self.assertTrue(sim_attr == set_attr and model_attr == set_attr)

        # dt
        set_attr = 5.
        athens_sim.set_options(dt=set_attr)
        sim_attr = athens_sim.configuration().dt
        model_attr = athens_sim._system_model.dt
        self.assertTrue(sim_attr == set_attr and model_attr == set_attr)
Example #6
0
    def test_set_meas_levels(self):
        """Test setting of meas_levels."""

        athens_backend = FakeAthens()
        athens_sim = PulseSimulator.from_backend(athens_backend)

        # test that a warning is thrown when meas_level 0 is attempted to be set
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")

            athens_sim.set_options(meas_levels=[0,1,2])

            self.assertEqual(len(w), 1)
            self.assertTrue('Measurement level 0 not supported' in str(w[-1].message))
            self.assertEqual(athens_sim.configuration().meas_levels, [1, 2])

        self.assertTrue(athens_sim.configuration().meas_levels == [1, 2])

        athens_sim.set_options(meas_levels=[2])
        self.assertTrue(athens_sim.configuration().meas_levels == [2])