def test_scheduling_pulse(instructions, method, expected_length, random_shuffle, gates_schedule): circuit = QubitCircuit(4) for instruction in instructions: circuit.add_gate( Gate(instruction.name, instruction.targets, instruction.controls)) if random_shuffle: repeat_num = 5 else: repeat_num = 0 result0 = gate_sequence_product(circuit.propagators()) # run the scheduler scheduler = Scheduler(method) gate_cycle_indices = scheduler.schedule(instructions, gates_schedule=gates_schedule, repeat_num=repeat_num) # check if the scheduled length is expected assert (max(gate_cycle_indices) == expected_length) scheduled_gate = [[] for i in range(max(gate_cycle_indices) + 1)] # check if the scheduled circuit is correct for i, cycles in enumerate(gate_cycle_indices): scheduled_gate[cycles].append(circuit.gates[i]) circuit.gates = sum(scheduled_gate, []) result1 = gate_sequence_product(circuit.propagators()) assert (tracedist(result0 * result1.dag(), qeye(result0.dims[0])) < 1.0e-7)
def test_scheduling_gates4(circuit, method, expected_length, random_shuffle, gates_schedule): if random_shuffle: repeat_num = 5 else: repeat_num = 0 result0 = gate_sequence_product(circuit.propagators()) # run the scheduler scheduler = Scheduler(method) gate_cycle_indices = scheduler.schedule(circuit, gates_schedule=gates_schedule, repeat_num=repeat_num) assert max(gate_cycle_indices) == expected_length _verify_scheduled_circuit(circuit, gate_cycle_indices)
def test_scheduling_pulse(instructions, method, expected_length, random_shuffle, gates_schedule): circuit = QubitCircuit(4) for instruction in instructions: circuit.add_gate( Gate(instruction.name, instruction.targets, instruction.controls)) if random_shuffle: repeat_num = 5 else: repeat_num = 0 result0 = gate_sequence_product(circuit.propagators()) # run the scheduler scheduler = Scheduler(method) gate_cycle_indices = scheduler.schedule(instructions, gates_schedule=gates_schedule, repeat_num=repeat_num) assert max(gate_cycle_indices) == expected_length
def test_allow_permutation(): circuit = QubitCircuit(2) circuit.add_gate("X", 0) circuit.add_gate("CNOT", 0, 1) circuit.add_gate("X", 1) result0 = gate_sequence_product(circuit.propagators()) scheduler = Scheduler("ASAP", allow_permutation=True) gate_cycle_indices = scheduler.schedule(circuit) assert (max(gate_cycle_indices) + 1) == 2 scheduler = Scheduler("ASAP", allow_permutation=False) gate_cycle_indices = scheduler.schedule(circuit) assert (max(gate_cycle_indices) + 1) == 3
processor.add_noise( RelaxationNoise(t2=30)) # Section 4.1 Model model = SpinChainModel( num_qubits=3, setup="circular", g=1) processor = Processor(model=model) model.get_control(label="sx0") model.get_control_labels() # Section 4.3 Scheduler from qutip_qip.compiler import Scheduler, Instruction Scheduler("ASAP").schedule(qc) inst_list = [] for gate in qc.gates: if gate.name in ("SNOT", "X"): inst_list.append( Instruction(gate, duration=1 ) ) else: inst_list.append( Instruction(gate, duration=2 ) ) Scheduler("ALAP").schedule(inst_list)
def test_commutation_rules(circuit, expected_length): scheduler = Scheduler("ASAP") gate_cycle_indices = scheduler.schedule(circuit) assert (max(gate_cycle_indices) + 1) == expected_length assert _verify_scheduled_circuit(circuit, gate_cycle_indices)