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)
def test_set_system_model_in_constructor(self): """Test setting system model when constructing.""" 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)]] # construct directly test_sim = None # construct backend and verify no warnings with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") test_sim = PulseSimulator(system_model=system_model) self.assertEqual(len(w), 0) # check that system model properties have been imported self.assertEqual(test_sim.configuration().dt, system_model.dt) self.assertEqual(test_sim.configuration().u_channel_lo, system_model.u_channel_lo)