Ejemplo n.º 1
0
 def setUp(self):
     super().setUp()
     instruction_durations = InstructionDurations()
     instruction_durations.update(
         [
             ("rz", (0,), 0),
             ("rz", (1,), 0),
             ("x", (0,), 160),
             ("x", (1,), 160),
             ("sx", (0,), 160),
             ("sx", (1,), 160),
             ("cx", (0, 1), 800),
             ("cx", (1, 0), 800),
             ("measure", None, 1600),
         ]
     )
     self.time_conversion_pass = TimeUnitConversion(inst_durations=instruction_durations)
     # reproduce old behavior of 0.20.0 before #7655
     # currently default write latency is 0
     self.scheduling_pass = ALAPSchedule(
         durations=instruction_durations,
         clbit_write_latency=1600,
         conditional_latency=0,
     )
     self.align_measure_pass = AlignMeasures(alignment=16)
Ejemplo n.º 2
0
def execute_sched(qc_list, backend, simulator, shots_single, shots_multi, xtalk_prop, save_path=None):
    
    instruction_durations = InstructionDurations.from_backend(backend)

    ## transpile each experiments
    # simulator
    multi_sim = multi_transpile(qc_list, backend=simulator)
    # non Scheduled
    single_nonsched, multi_nonsched = single_parallel_transpile(qc_list, backend=backend, layout_method='xtalk_adaptive',  instruction_durations=instruction_durations, xtalk_prop=xtalk_prop)
    # ALAP Scheduled
    single_alap, multi_alap = single_parallel_transpile(qc_list, backend=backend, layout_method='xtalk_adaptive', scheduling_method='as_late_as_possible', instruction_durations=instruction_durations, xtalk_prop=xtalk_prop)
    

    # execute each experiments
    job_sim = _execute(sigle_exp=qc_list, multi_exp=multi_sim, backend=simulator, shots_single=shots_single, shots_multi=shots_multi)
    job_nonsched = _execute(sigle_exp=single_nonsched, multi_exp=multi_nonsched, backend=backend, shots_single=shots_single, shots_multi=shots_multi)
    job_alap = _execute(sigle_exp=single_alap, multi_exp=multi_alap, backend=backend, shots_single=shots_single, shots_multi=shots_multi)
    

    if save_path: 
        _save_experiments( 
            qc_list, multi_sim, job_sim, 
            single_nonsched, multi_nonsched, job_nonsched, 
            single_alap, multi_alap, job_alap, 
            backend, shots_single, shots_multi, save_path)

    return job_sim, job_nonsched, job_alap
Ejemplo n.º 3
0
def test_multi_alap():
    qr0 = QuantumRegister(2)
    qr1 = QuantumRegister(2)
    qc = QuantumCircuit(qr0, qr1)

    qc.cx(qr0[0], qr0[1])

    qc.cx(qr1[0], qr1[1])
    qc.cx(qr1[1], qr1[0])
    qc.cx(qr1[0], qr1[1])

    qc.measure_all()

    layout = Layout({
        qr0[0]: 0,
        qr0[1]: 1,
        qr1[0]: 2,
        qr1[1]: 3,
    })
    durations = InstructionDurations([('cx', None, 1000),
                                      ('measure', None, 1000)])

    transpiled_qc = transpile(qc, initial_layout=layout)
    dag = circuit_to_dag(transpiled_qc)

    malap_dag = MultiALAPSchedule(durations).run(dag, time_unit="dt")

    print(dag_to_circuit(malap_dag))
    assert (malap_dag.duration == 4000)
 def setUp(self):
     super().setUp()
     instruction_durations = InstructionDurations()
     instruction_durations.update([
         ("rz", (0, ), 0),
         ("rz", (1, ), 0),
         ("x", (0, ), 160),
         ("x", (1, ), 160),
         ("sx", (0, ), 160),
         ("sx", (1, ), 160),
         ("cx", (0, 1), 800),
         ("cx", (1, 0), 800),
         ("measure", None, 1600),
     ])
     self.time_conversion_pass = TimeUnitConversion(
         inst_durations=instruction_durations)
     self.scheduling_pass = ALAPSchedule(durations=instruction_durations)
     self.align_measure_pass = AlignMeasures(alignment=16)
Ejemplo n.º 5
0
    def setUp(self):
        super().setUp()

        self.instruction_durations = InstructionDurations([
            ("rz", (0, ), 0),
            ("rz", (1, ), 0),
            ("x", (0, ), 160),
            ("x", (1, ), 160),
            ("sx", (0, ), 160),
            ("sx", (1, ), 160),
            ("cx", (0, 1), 800),
            ("cx", (1, 0), 800),
            ("measure", None, 1600),
        ])
Ejemplo n.º 6
0
def test_execute_alap(): 
    simulator = get_IBM_backend('ibmq_qasm_simulator')
    backend = get_IBM_backend('ibmq_paris')
    instruction_durations = InstructionDurations.from_backend(backend)
    path = str(os.getcwd()) + '/test_jobfile/test_alap_job.pickle'
    execute_alap(
        size='small', 
        names=['toffoli_n3', 'adder_n4 '], 
        backend=backend, 
        simulator=simulator,
        shots = 1000, 
        nseed=1,
        save_path=path,
        instruction_durations=instruction_durations
        )
Ejemplo n.º 7
0
 def setup(self, n_qubits, depth):
     seed = 42
     self.circuit = random_circuit(n_qubits,
                                   depth,
                                   measure=True,
                                   conditional=True,
                                   reset=True,
                                   seed=seed,
                                   max_operands=2)
     self.basis_gates = ['rz', 'sx', 'x', 'cx', 'id', 'reset']
     self.cmap = [[0, 1], [1, 0], [1, 2], [1, 6], [2, 1], [2, 3], [3, 2],
                  [3, 4], [3, 8], [4, 3], [5, 6], [5, 10], [6, 1], [6, 5],
                  [6, 7], [7, 6], [7, 8], [7, 12], [8, 3], [8, 7], [8, 9],
                  [9, 8], [9, 14], [10, 5], [10, 11], [11, 10], [11, 12],
                  [11, 16], [12, 7], [12, 11], [12, 13], [13, 12], [13, 14],
                  [13, 18], [14, 9], [14, 13], [15, 16], [16, 11], [16, 15],
                  [16, 17], [17, 16], [17, 18], [18, 13], [18, 17],
                  [18, 19], [19, 18]]
     self.coupling_map = CouplingMap(self.cmap)
     self.transpiled_circuit = transpile(self.circuit,
                                         basis_gates=self.basis_gates,
                                         coupling_map=self.coupling_map,
                                         optimization_level=1)
     self.dag = circuit_to_dag(self.transpiled_circuit)
     self.durations = InstructionDurations([
         ("rz", None, 0),
         ("id", None, 160),
         ("sx", None, 160),
         ("x", None, 160),
         ("cx", None, 800),
         ("measure", None, 3200),
         ("reset", None, 3600),
     ],
                                           dt=1e-9)
     self.timed_dag = TimeUnitConversion(self.durations).run(self.dag)
     _pass = ALAPSchedule(self.durations)
     _pass.property_set['time_unit'] = "dt"
     self.scheduled_dag = _pass.run(self.timed_dag)
Ejemplo n.º 8
0
    def load_program(self, program: circuit.QuantumCircuit):
        """Load quantum circuit and create drawing..

        Args:
            program: Scheduled circuit object to draw.

        Raises:
           VisualizationError: When circuit is not scheduled.
        """
        not_gate_like = (circuit.Barrier, )

        if getattr(program, "_op_start_times") is None:
            # Run scheduling for backward compatibility
            from qiskit import transpile
            from qiskit.transpiler import InstructionDurations, TranspilerError

            warnings.warn(
                "Visualizing un-scheduled circuit with timeline drawer has been deprecated. "
                "This circuit should be transpiled with scheduler though it consists of "
                "instructions with explicit durations.",
                DeprecationWarning,
            )

            try:
                program = transpile(
                    program,
                    scheduling_method="alap",
                    instruction_durations=InstructionDurations())
            except TranspilerError as ex:
                raise VisualizationError(
                    f"Input circuit {program.name} is not scheduled and it contains "
                    "operations with unknown delays. This cannot be visualized."
                ) from ex

        for t0, instruction in zip(program.op_start_times, program.data):
            bits = list(instruction.qubits) + list(instruction.clbits)
            for bit_pos, bit in enumerate(bits):
                if not isinstance(instruction.operation, not_gate_like):
                    # Generate draw object for gates
                    gate_source = types.ScheduledGate(
                        t0=t0,
                        operand=instruction.operation,
                        duration=instruction.operation.duration,
                        bits=bits,
                        bit_position=bit_pos,
                    )
                    for gen in self.generator["gates"]:
                        obj_generator = partial(gen, formatter=self.formatter)
                        for datum in obj_generator(gate_source):
                            self.add_data(datum)
                    if len(bits) > 1 and bit_pos == 0:
                        # Generate draw object for gate-gate link
                        line_pos = t0 + 0.5 * instruction.operation.duration
                        link_source = types.GateLink(
                            t0=line_pos,
                            opname=instruction.operation.name,
                            bits=bits)
                        for gen in self.generator["gate_links"]:
                            obj_generator = partial(gen,
                                                    formatter=self.formatter)
                            for datum in obj_generator(link_source):
                                self.add_data(datum)
                if isinstance(instruction.operation, circuit.Barrier):
                    # Generate draw object for barrier
                    barrier_source = types.Barrier(t0=t0,
                                                   bits=bits,
                                                   bit_position=bit_pos)
                    for gen in self.generator["barriers"]:
                        obj_generator = partial(gen, formatter=self.formatter)
                        for datum in obj_generator(barrier_source):
                            self.add_data(datum)

        self.bits = list(program.qubits) + list(program.clbits)
        for bit in self.bits:
            for gen in self.generator["bits"]:
                # Generate draw objects for bit
                obj_generator = partial(gen, formatter=self.formatter)
                for datum in obj_generator(bit):
                    self.add_data(datum)

        # update time range
        t_end = max(program.duration,
                    self.formatter["margin.minimum_duration"])
        self.set_time_range(t_start=0, t_end=t_end)
Ejemplo n.º 9
0
 def setup(self, _):
     self.rochester_coupling_map = [
         [0, 5],
         [0, 1],
         [1, 2],
         [1, 0],
         [2, 3],
         [2, 1],
         [3, 4],
         [3, 2],
         [4, 6],
         [4, 3],
         [5, 9],
         [5, 0],
         [6, 13],
         [6, 4],
         [7, 16],
         [7, 8],
         [8, 9],
         [8, 7],
         [9, 10],
         [9, 8],
         [9, 5],
         [10, 11],
         [10, 9],
         [11, 17],
         [11, 12],
         [11, 10],
         [12, 13],
         [12, 11],
         [13, 14],
         [13, 12],
         [13, 6],
         [14, 15],
         [14, 13],
         [15, 18],
         [15, 14],
         [16, 19],
         [16, 7],
         [17, 23],
         [17, 11],
         [18, 27],
         [18, 15],
         [19, 20],
         [19, 16],
         [20, 21],
         [20, 19],
         [21, 28],
         [21, 22],
         [21, 20],
         [22, 23],
         [22, 21],
         [23, 24],
         [23, 22],
         [23, 17],
         [24, 25],
         [24, 23],
         [25, 29],
         [25, 26],
         [25, 24],
         [26, 27],
         [26, 25],
         [27, 26],
         [27, 18],
         [28, 32],
         [28, 21],
         [29, 36],
         [29, 25],
         [30, 39],
         [30, 31],
         [31, 32],
         [31, 30],
         [32, 33],
         [32, 31],
         [32, 28],
         [33, 34],
         [33, 32],
         [34, 40],
         [34, 35],
         [34, 33],
         [35, 36],
         [35, 34],
         [36, 37],
         [36, 35],
         [36, 29],
         [37, 38],
         [37, 36],
         [38, 41],
         [38, 37],
         [39, 42],
         [39, 30],
         [40, 46],
         [40, 34],
         [41, 50],
         [41, 38],
         [42, 43],
         [42, 39],
         [43, 44],
         [43, 42],
         [44, 51],
         [44, 45],
         [44, 43],
         [45, 46],
         [45, 44],
         [46, 47],
         [46, 45],
         [46, 40],
         [47, 48],
         [47, 46],
         [48, 52],
         [48, 49],
         [48, 47],
         [49, 50],
         [49, 48],
         [50, 49],
         [50, 41],
         [51, 44],
         [52, 48]]
     self.basis_gates = ['u1', 'u2', 'u3', 'cx', 'id']
     self.qv_50_x_20 = build_qv_model_circuit(50, 20, 0)
     self.qv_14_x_14 = build_qv_model_circuit(14, 14, 0)
     self.qasm_path = os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'qasm'))
     large_qasm_path = os.path.join(self.qasm_path, 'test_eoh_qasm.qasm')
     self.large_qasm = QuantumCircuit.from_qasm_file(large_qasm_path)
     self.melbourne = FakeMelbourne()
     self.durations = InstructionDurations([
         ("u1", None, 0),
         ("id", None, 160),
         ("u2", None, 160),
         ("u3", None, 320),
         ("cx", None, 800),
         ("measure", None, 3200),
     ], dt=1e-9)