1
$\begingroup$

I'm trying to run a quantum circuit created in Qiskit, on Ionq Device using qiskit_braket_provider. Getting some error while transpiling the circuit because circuit contains a qiskit.initialize instruction. Is there any alternative for initialize function in aws braket? Any other way out of this problem?

This problem can be recreated as:

Code:

qc = QuantumCircuit(2)
st = random_statevector(2)
qc.initialize(st, 0)
qc.x(1)
tqc = transpile(qc,backend = ionq)

Error:

TranspilerError                           Traceback (most recent call last)
Input In [66], in <cell line: 1>()
----> 1 tqc = transpile(qc,backend = ionq)

File ~/anaconda3/envs/qlab/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/qlab/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/qlab/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/qlab/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/qlab/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/qlab/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/qlab/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/qlab/lib/python3.10/site-packages/qiskit/transpiler/runningpassmanager.py:196, in RunningPassManager._run_this_pass(self, pass_, dag)
    193 if pass_.is_transformation_pass:
    194     # Measure time if we have a callback or logging set
    195     start_time = time()
--> 196     new_dag = pass_.run(dag)
    197     end_time = time()
    198     run_time = end_time - start_time

File ~/anaconda3/envs/qlab/lib/python3.10/site-packages/qiskit/transpiler/passes/basis/basis_translator.py:184, in BasisTranslator.run(self, dag)
    179 logger.info(
    180     "Basis translation path search completed in %.3fs.", search_end_time - search_start_time
    181 )
    183 if basis_transforms is None:
--> 184     raise TranspilerError(
    185         "Unable to map source basis {} to target basis {} "
    186         "over library {}.".format(source_basis, target_basis, self._equiv_lib)
    187     )
    189 # Compose found path into a set of instruction substitution rules.
    191 compose_start_time = time.time()

TranspilerError: "Unable to map source basis {('reset', 1), ('x', 1), ('rz', 1), ('ry', 1)} to target basis {'h', 'rzz', 's', 'sdg', 'tdg', 'rz', 'swap', 'barrier', 'cx', 'x', 'id', 'z', 'sx', 'sxdg', 'y', 'measure', 't', 'rxx', 'rx', 'ryy', 'snapshot', 'ry'} over library <qiskit.circuit.equivalence.EquivalenceLibrary object at 0x7f0900dd5ea0>."
```
$\endgroup$

1 Answer 1

2
$\begingroup$

It seems the target device does not support resets. Since the initialization is the first instruction, you could use the state_preparation method if you are sure that the qubits are initialized in the $|0\rangle$ state.

qc = QuantumCircuit(2)
st = random_statevector(2)
qc.prepare_state(st, 0)
qc.x(1)
tqc = transpile(qc, backend=ionq)
$\endgroup$
1
  • $\begingroup$ Thanks! state_preparation worked. $\endgroup$
    – Devesh
    Commented Aug 24, 2022 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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