def test_assemble_with_individual_discriminators(self): """Test that assembly works with individual discriminators.""" disc_one = Discriminator('disc_one', test_params=True) disc_two = Discriminator('disc_two', test_params=False) schedule = Schedule() schedule = schedule.append( Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one), ) schedule = schedule.append( Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two), ) qobj = assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0, 1]]) validate_qobj_against_schema(qobj) qobj_discriminators = qobj.experiments[0].instructions[0].discriminators self.assertEqual(len(qobj_discriminators), 2) self.assertEqual(qobj_discriminators[0].name, 'disc_one') self.assertEqual(qobj_discriminators[0].params['test_params'], True) self.assertEqual(qobj_discriminators[1].name, 'disc_two') self.assertEqual(qobj_discriminators[1].params['test_params'], False)
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 = Acquire(10, AcquireChannel(0), MemorySlot(0), kernel=kernel, discriminator=discriminator, name='acquire') self.assertEqual(acq.duration, 10) self.assertEqual(acq.discriminator.name, 'linear_discriminator') self.assertEqual(acq.discriminator.params, discriminator_opts) self.assertEqual(acq.kernel.name, 'boxcar') self.assertEqual(acq.kernel.params, kernel_opts) self.assertIsInstance(acq.id, int) self.assertEqual(acq.name, 'acquire') self.assertEqual(acq.operands, (10, AcquireChannel(0), MemorySlot(0), None))
def test_assemble_with_unequal_discriminators(self): """Test that assembly works with incorrect number of discriminators for number of qubits.""" disc_one = Discriminator('disc_one', test_params=True) disc_two = Discriminator('disc_two', test_params=False) schedule = Schedule() schedule += Acquire(5, AcquireChannel(0), MemorySlot(0), discriminator=disc_one) schedule += Acquire(5, AcquireChannel(1), MemorySlot(1), discriminator=disc_two) schedule += Acquire(5, AcquireChannel(2), MemorySlot(2)) with self.assertRaises(QiskitError): assemble(schedule, qubit_lo_freq=self.default_qubit_lo_freq, meas_lo_freq=self.default_meas_lo_freq, meas_map=[[0, 1, 2]])
def test_isntructions_hash(self): """Test hashing for acquire instruction.""" 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_1 = Acquire(10, AcquireChannel(0), MemorySlot(0), kernel=kernel, discriminator=discriminator, name='acquire') acq_2 = Acquire(10, AcquireChannel(0), MemorySlot(0), kernel=kernel, discriminator=discriminator, name='acquire') hash_1 = hash(acq_1) hash_2 = hash(acq_2) self.assertEqual(hash_1, hash_2)
def convert_acquire(self, instruction): """Return converted `Acquire`. Args: instruction (PulseQobjInstruction): acquire qobj Returns: Schedule: Converted and scheduled Instruction """ t0 = instruction.t0 duration = instruction.duration qubits = instruction.qubits acquire_channels = [channels.AcquireChannel(qubit) for qubit in qubits] mem_slots = [channels.MemorySlot(instruction.memory_slot[i]) for i in range(len(qubits))] if hasattr(instruction, 'register_slot'): register_slots = [channels.RegisterSlot(instruction.register_slot[i]) for i in range(len(qubits))] else: register_slots = [None] * len(qubits) discriminators = (instruction.discriminators if hasattr(instruction, 'discriminators') else None) if not isinstance(discriminators, list): discriminators = [discriminators] if any(discriminators[i] != discriminators[0] for i in range(len(discriminators))): warnings.warn("Can currently only support one discriminator per acquire. Defaulting " "to first discriminator entry.") discriminator = discriminators[0] if discriminator: discriminator = Discriminator(name=discriminators[0].name, **discriminators[0].params) kernels = (instruction.kernels if hasattr(instruction, 'kernels') else None) if not isinstance(kernels, list): kernels = [kernels] if any(kernels[0] != kernels[i] for i in range(len(kernels))): warnings.warn("Can currently only support one kernel per acquire. Defaulting to first " "kernel entry.") kernel = kernels[0] if kernel: kernel = Kernel(name=kernels[0].name, **kernels[0].params) schedule = Schedule() for acquire_channel, mem_slot, reg_slot in zip(acquire_channels, mem_slots, register_slots): schedule |= instructions.Acquire(duration, acquire_channel, mem_slot=mem_slot, reg_slot=reg_slot, kernel=kernel, discriminator=discriminator) << t0 return schedule