def test_default(self): """Test default discriminator and kernel. """ kernel_opts = {'start_window': 0, 'stop_window': 10} kernel = Kernel(name='boxcar', **kernel_opts) discriminator_opts = { 'neighborhoods': [{ 'qubits': 1, 'channels': 1 }], 'cal': 'coloring', 'resample': False } discriminator = Discriminator(name='linear_discriminator', **discriminator_opts) acq_command = Acquire(duration=10, kernel=kernel, discriminator=discriminator) self.assertEqual(acq_command.duration, 10) self.assertEqual(acq_command.discriminator.name, 'linear_discriminator') self.assertEqual(acq_command.discriminator.params, discriminator_opts) self.assertEqual(acq_command.kernel.name, 'boxcar') self.assertEqual(acq_command.kernel.params, kernel_opts)
def test_can_construct_valid_acquire_command(self): """Test if valid acquire command can be constructed. """ kernel_opts = {'start_window': 0, 'stop_window': 10} kernel = Kernel(name='boxcar', **kernel_opts) discriminator_opts = { 'neighborhoods': [{ 'qubits': 1, 'channels': 1 }], 'cal': 'coloring', 'resample': False } discriminator = Discriminator(name='linear_discriminator', **discriminator_opts) acq_command = Acquire(duration=10, kernel=kernel, discriminator=discriminator) self.assertEqual(acq_command.duration, 10) self.assertEqual(acq_command.discriminator.name, 'linear_discriminator') self.assertEqual(acq_command.discriminator.params, discriminator_opts) self.assertEqual(acq_command.kernel.name, 'boxcar') self.assertEqual(acq_command.kernel.params, kernel_opts) self.assertTrue(acq_command.name.startswith('acq'))
def test_can_construct_kernel_with_default_values(self): """Test if Kernel can be constructed with default name and params. """ kernel = Kernel() self.assertEqual(kernel.name, None) self.assertEqual(kernel.params, {})
def test_acquire(self): """Test converted qobj from Acquire.""" schedule = Schedule() for i in range(self.num_qubits): schedule |= Acquire( 10, AcquireChannel(i), MemorySlot(i), RegisterSlot(i), kernel=Kernel(name="test_kern", test_params="test"), discriminator=Discriminator(name="test_disc", test_params=1.0), ) qobj = PulseQobjInstruction( name="acquire", t0=0, duration=10, qubits=[0, 1], memory_slot=[0, 1], register_slot=[0, 1], kernels=[ QobjMeasurementOption(name="test_kern", params={"test_params": "test"}) ], discriminators=[ QobjMeasurementOption(name="test_disc", params={"test_params": 1.0}) ], ) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.start_time, 0) self.assertEqual(converted_instruction.duration, 10) self.assertEqual(converted_instruction.instructions[0][-1].duration, 10) self.assertEqual( converted_instruction.instructions[0][-1].kernel.params, {"test_params": "test"}) self.assertEqual(converted_instruction.instructions[1][-1].channel, AcquireChannel(1))
def test_acquire(self): """Test converted qobj from Acquire.""" schedule = Schedule() for i in range(self.num_qubits): schedule |= Acquire(10, AcquireChannel(i), MemorySlot(i), RegisterSlot(i), kernel=Kernel(name='test_kern', test_params='test'), discriminator=Discriminator(name='test_disc', test_params=1.0)) qobj = PulseQobjInstruction(name='acquire', t0=0, duration=10, qubits=[0, 1], memory_slot=[0, 1], register_slot=[0, 1], kernels=[QobjMeasurementOption( name='test_kern', params={'test_params': 'test'})], discriminators=[QobjMeasurementOption( name='test_disc', params={'test_params': 1.0})]) converted_instruction = self.converter(qobj) self.assertEqual(converted_instruction.timeslots, schedule.timeslots) self.assertEqual(converted_instruction.instructions[0][-1].duration, 10) self.assertEqual(converted_instruction.instructions[0][-1].kernel.params, {'test_params': 'test'}) self.assertEqual(converted_instruction.instructions[1][-1].channel, AcquireChannel(1))