2
$\begingroup$

The following error occurs when executing the code to measure the dephasing time(T2). I would appreciate it if someone could give me a solution to this problem. Among the two functions below, widthoutDelay() performs normally, and the function withDelay() fails with the attached error.

Additionally, where can I find an example code to measure the time-dependent dephasing of the qubit? Some of the sample codes are from a few years ago, so there are a lot of contents that have been depreciated.

--------------------------- Execution Code in jupyter ---------------------------

from qiskit import QuantumRegister, ClassicalRegister
from qiskit import QuantumCircuit, execute,IBMQ
from qiskit.tools.monitor import job_monitor
from qiskit import transpile
import numpy

pi = numpy.pi

IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q')
backend = provider.get_backend('ibm_nairobi')

q = QuantumRegister(1,'q')
c = ClassicalRegister(1,'c')

def withoutDelay():
    circuit = QuantumCircuit(q,c)

    circuit.h(q[0])
    circuit.h(q[0])
    circuit.measure(q[0],c[0]) #Measuring the qubit

    nShots = 8192

    job = execute(circuit, backend, shots=nShots)
    job_monitor(job)

    counts = job.result().get_counts()

    print("No delay: ",counts)

def withDelay():  
    circuit = QuantumCircuit(q,c)
    circuit.h(q[0])
    circuit.delay(283, unit="us") # Delay of 200.79 microseconds   
    circuit.h(q[0])

    circuit.measure(q[0],c[0]) #Measuring the qubit

    transpiled_circ = transpile(circuit, backend, scheduling_method='alap')  

    nShots = 8192
    
    job = execute(transpiled_circ, backend, shots=nShots)
    job_monitor(job)

    counts = job.result().get_counts()

    print("With delay: ",counts)

withoutDelay()
withDelay()

--------------------------- Error Message ---------------------------

Job Status: job has successfully run
No delay:  {'0': 8111, '1': 81}

---------------------------------------------------------------------------
TranspilerError                           Traceback (most recent call last)
Input In [19], in ()
     49     print("With delay: ",counts)
     51 withoutDelay()
---> 52 withDelay()

Input In [19], in withDelay()
     40 transpiled_circ = transpile(circuit, backend, scheduling_method='alap')  
     42 nShots = 8192
---> 44 job = execute(transpiled_circ, backend, shots=nShots)
     45 job_monitor(job)
     47 counts = job.result().get_counts()

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/execute_function.py:299, in execute(experiments, backend, basis_gates, coupling_map, backend_properties, initial_layout, seed_transpiler, optimization_level, pass_manager, qobj_id, qobj_header, shots, memory, max_credits, seed_simulator, default_qubit_los, default_meas_los, qubit_lo_range, meas_lo_range, schedule_los, meas_level, meas_return, memory_slots, memory_slot_size, rep_time, rep_delay, parameter_binds, schedule_circuit, inst_map, meas_map, scheduling_method, init_qubits, **run_config)
    296     experiments = pass_manager.run(experiments)
    297 else:
    298     # transpiling the circuits using given transpile options
--> 299     experiments = transpile(
    300         experiments,
    301         basis_gates=basis_gates,
    302         coupling_map=coupling_map,
    303         backend_properties=backend_properties,
    304         initial_layout=initial_layout,
    305         seed_transpiler=seed_transpiler,
    306         optimization_level=optimization_level,
    307         backend=backend,
    308     )
    310 if schedule_circuit:
    311     experiments = schedule(
    312         circuits=experiments,
    313         backend=backend,
   (...)
    316         method=scheduling_method,
    317     )

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/compiler/transpiler.py:341, in transpile(circuits, backend, basis_gates, inst_map, coupling_map, backend_properties, initial_layout, layout_method, routing_method, translation_method, scheduling_method, instruction_durations, dt, approximation_degree, timing_constraints, seed_transpiler, optimization_level, callback, output_name, unitary_synthesis_method, unitary_synthesis_plugin_config, target)
    338     for circuit, unique_args in zip(circuits, unique_transpile_args):
    339         transpile_config, pass_manager = _combine_args(shared_args, unique_args)
    340         output_circuits.append(
--> 341             _serial_transpile_circuit(
    342                 circuit,
    343                 pass_manager,
    344                 transpile_config["callback"],
    345                 transpile_config["output_name"],
    346                 transpile_config["backend_num_qubits"],
    347                 transpile_config["faulty_qubits_map"],
    348                 transpile_config["pass_manager_config"].backend_properties,
    349             )
    350         )
    351     circuits = output_circuits
    352 end_time = time()

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/compiler/transpiler.py:434, in _serial_transpile_circuit(circuit, pass_manager, callback, output_name, num_qubits, faulty_qubits_map, backend_prop)
    425 def _serial_transpile_circuit(
    426     circuit,
    427     pass_manager,
   (...)
    432     backend_prop=None,
    433 ):
--> 434     result = pass_manager.run(circuit, callback=callback, output_name=output_name)
    435     if faulty_qubits_map:
    436         return _remap_circuit_faulty_backend(
    437             result,
    438             num_qubits,
    439             backend_prop,
    440             faulty_qubits_map,
    441         )

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/transpiler/passmanager.py:507, in StagedPassManager.run(self, circuits, output_name, callback)
    500 def run(
    501     self,
    502     circuits: Union[QuantumCircuit, List[QuantumCircuit]],
    503     output_name: str = None,
    504     callback: Callable = None,
    505 ) -> Union[QuantumCircuit, List[QuantumCircuit]]:
    506     self._update_passmanager()
--> 507     return super().run(circuits, output_name, callback)

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/transpiler/passmanager.py:224, in PassManager.run(self, circuits, output_name, callback)
    222     return circuits
    223 if isinstance(circuits, QuantumCircuit):
--> 224     return self._run_single_circuit(circuits, output_name, callback)
    225 if len(circuits) == 1:
    226     return self._run_single_circuit(circuits[0], output_name, callback)

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/transpiler/passmanager.py:279, in PassManager._run_single_circuit(self, circuit, output_name, callback)
    267 """Run all the passes on a ``circuit``.
    268 
    269 Args:
   (...)
    276     The transformed circuit.
    277 """
    278 running_passmanager = self._create_running_passmanager()
--> 279 result = running_passmanager.run(circuit, output_name=output_name, callback=callback)
    280 self.property_set = running_passmanager.property_set
    281 return result

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/transpiler/runningpassmanager.py:124, in RunningPassManager.run(***failed resolving arguments***)
    122 for passset in self.working_list:
    123     for pass_ in passset:
--> 124         dag = self._do_pass(pass_, dag, passset.options)
    126 circuit = dag_to_circuit(dag)
    127 if output_name:

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/transpiler/runningpassmanager.py:167, in RunningPassManager._do_pass(self, pass_, dag, options)
    165 # Run the pass itself, if not already run
    166 if pass_ not in self.valid_passes:
--> 167     dag = self._run_this_pass(pass_, dag)
    169     # update the valid_passes property
    170     self._update_valid_passes(pass_)

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/transpiler/runningpassmanager.py:221, in RunningPassManager._run_this_pass(self, pass_, dag)
    218 elif pass_.is_analysis_pass:
    219     # Measure time if we have a callback or logging set
    220     start_time = time()
--> 221     pass_.run(FencedDAGCircuit(dag))
    222     end_time = time()
    223     run_time = end_time - start_time

File ~/anaconda3/envs/qiskit/lib/python3.10/site-packages/qiskit/transpiler/passes/scheduling/alignments/reschedule.py:206, in ConstrainedReschedule.run(self, dag)
    170 """Run rescheduler.
    171 
    172 This pass should perform rescheduling to satisfy:
   (...)
    202     TranspilerError: If circuit is not scheduled.
    203 """
    205 if "node_start_time" not in self.property_set:
--> 206     raise TranspilerError(
    207         f"The input circuit {dag.name} is not scheduled. Call one of scheduling passes "
    208         f"before running the {self.__class__.__name__} pass."
    209     )
    211 node_start_time = self.property_set["node_start_time"]
    213 for node in dag.topological_op_nodes():

TranspilerError: 'The input circuit None is not scheduled. Call one of scheduling passes before running the ConstrainedReschedule pass.'
$\endgroup$

1 Answer 1

1
$\begingroup$

The issue with your withDelay function is its use of execute (which combines transpile and backend.run into a single function call). When you're calling execute, it's the equivalent of running transpile again without specifying a scheduling method.

You can fix the issue simply by changing execute to backend.run, so the revised withDelay function would look as follows:

def withDelay():  
    circuit = QuantumCircuit(q,c)
    circuit.h(q[0])
    circuit.delay(283, unit="us") # Delay of 200.79 microseconds   
    circuit.h(q[0])

    circuit.measure(q[0],c[0]) #Measuring the qubit

    transpiled_circ = transpile(circuit, backend, scheduling_method='alap')  

    nShots = 8192
    
    job = backend.run(transpiled_circ, shots=nShots)
    job_monitor(job)

    counts = job.result().get_counts()

    print("With delay: ",counts)

See related issue: Transpiler error during execution of circuits... #7317

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.