0
$\begingroup$

https://learn.qiskit.org/summer-school/2021/lab4-introduction-training-quantum-circuits

  > TranspilerError                           Traceback (most recent call
    > last) File
    > d:\miniconda3\lib\site-packages\qiskit\opflow\gradients\circuit_gradients\circuit_gradient.py:92,
    > in CircuitGradient._transpile_to_supported_operations(circuit,
    > supported_gates)
    >      91 try:
    > ---> 92     circuit = transpile(
    >      93         circuit, basis_gates=list(supported_gates), optimization_level=0
    >      94     )
    >      95 except Exception as exc:
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\compiler\transpiler.py:304, 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)
    >     303 # Transpile circuits in parallel
    > --> 304 circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_args)))
    >     306 end_time = time()
    > 
    > File d:\miniconda3\lib\site-packages\qiskit\tools\parallel.py:129, in
    > parallel_map(task, values, task_args, task_kwargs, num_processes)
    >     128 if len(values) == 1:
    > --> 129     return [task(values[0], *task_args, **task_kwargs)]
    >     131 Publisher().publish("terra.parallel.start", len(values))
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\compiler\transpiler.py:389, in
    > _transpile_circuit(circuit_config_tuple)
    >     387     raise TranspilerError("optimization_level can range from 0 to 3.")
    > --> 389 result = pass_manager.run(
    >     390     circuit, callback=transpile_config["callback"], output_name=transpile_config["output_name"]
    >     391 )
    >     393 if transpile_config["faulty_qubits_map"]:
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\transpiler\passmanager.py:222,
    > in PassManager.run(self, circuits, output_name, callback)
    >     221 if isinstance(circuits, QuantumCircuit):
    > --> 222     return self._run_single_circuit(circuits, output_name, callback)
    >     223 if len(circuits) == 1:
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\transpiler\passmanager.py:277,
    > in PassManager._run_single_circuit(self, circuit, output_name,
    > callback)
    >     276 running_passmanager = self._create_running_passmanager()
    > --> 277 result = running_passmanager.run(circuit, output_name=output_name, callback=callback)
    >     278 self.property_set = running_passmanager.property_set
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\transpiler\runningpassmanager.py:124,
    > in RunningPassManager.run(***failed resolving arguments***)
    >     123     for pass_ in passset:
    > --> 124         dag = self._do_pass(pass_, dag, passset.options)
    >     126 circuit = dag_to_circuit(dag)
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\transpiler\runningpassmanager.py:157,
    > in RunningPassManager._do_pass(self, pass_, dag, options)
    >     156 if pass_ not in self.valid_passes:
    > --> 157     dag = self._run_this_pass(pass_, dag)
    >     159     # update the valid_passes property
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\transpiler\runningpassmanager.py:186,
    > in RunningPassManager._run_this_pass(self, pass_, dag)
    >     185 start_time = time()
    > --> 186 new_dag = pass_.run(dag)
    >     187 end_time = time()
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\transpiler\passes\basis\basis_translator.py:206,
    > in BasisTranslator.run(self, dag)
    >     205 if basis_transforms is None:
    > --> 206     raise TranspilerError(
    >     207         "Unable to map source basis {} to target basis {} "
    >     208         "over library {}.".format(source_basis, target_basis, self._equiv_lib)
    >     209     )
    >     211 # Compose found path into a set of instruction substitution rules.
    > 
    > TranspilerError: "Unable to map source basis {('h', 1),
    > ('save_density_matrix', 3), ('swap', 2), ('ry', 1), ('ccx', 3),
    > ('barrier', 18), ('cx', 2)} to target basis {'rz', 'ry', 'y',
    > 'barrier', 'u', 'snapshot', 'h', 'z', 'measure', 'x', 'cx', 'delay',
    > 'cz', 'reset', 'p', 'rx', 'cy'} over library
    > <qiskit.circuit.equivalence.EquivalenceLibrary object at
    > 0x000001D80DDAD310>."
    > 
    > The above exception was the direct cause of the following exception:
    > 
    > QiskitError                               Traceback (most recent call
    > last) Input In [13], in <cell line: 41>()
    >      38 print(finite_difference)
    >      40 shifter = Gradient()  # parameter-shift rule is the default
    > ---> 41 grad = shifter.convert(expectation, params=QC.parameters[index])
    >      42 sampler.convert(grad, value_dict).eval().real
    >      44 tmp = init_states(num_words, qbits_for_single_word) 
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\opflow\gradients\gradient.py:78,
    > in Gradient.convert(self, operator, params)
    >      76 expec_op = PauliExpectation(group_paulis=False).convert(operator).reduce()
    >      77 cleaned_op = self._factor_coeffs_out_of_composed_op(expec_op)
    > ---> 78 return self.get_gradient(cleaned_op, param)
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\opflow\gradients\gradient.py:182,
    > in Gradient.get_gradient(self, operator, params)
    >     176     if not isinstance(operator[-1], CircuitStateFn):
    >     177         raise TypeError(
    >     178             "The gradient framework is compatible with states that are given as "
    >     179             "CircuitStateFn"
    >     180         )
    > --> 182     return self.grad_method.convert(operator, param)
    >     184 elif isinstance(operator, CircuitStateFn):
    >     185     # Gradient of an a state's sampling probabilities
    >     186     if not is_coeff_c(operator._coeff, 1.0):
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\opflow\gradients\circuit_gradients\param_shift.py:116,
    > in ParamShift.convert(self, operator, params)
    >      96 """
    >      97 Args:
    >      98     operator: The operator corresponding to our quantum state we are taking the    (...)
    >     113 
    >     114 """
    >     115 if isinstance(params, (ParameterExpression, ParameterVector)):
    > --> 116     return self._parameter_shift(operator, params)
    >     117 elif isinstance(params, tuple):
    >     118     return self._parameter_shift(self._parameter_shift(operator, params[0]),
    > params[1])
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\opflow\gradients\circuit_gradients\param_shift.py:202,
    > in ParamShift._parameter_shift(self, operator, params)
    >     197 circ = circs[0]
    >     199 if self.analytic:
    >     200     # Unroll the circuit into a gate set for which the gradient may be computed
    >     201     # using pi/2 shifts.
    > --> 202     circ = ParamShift._transpile_to_supported_operations(circ, self.SUPPORTED_GATES)
    >     203     operator = ParamShift._replace_operator_circuit(operator, circ)
    >     205 if param not in circ._parameter_table:
    > 
    > File
    > d:\miniconda3\lib\site-packages\qiskit\opflow\gradients\circuit_gradients\circuit_gradient.py:96,
    > in CircuitGradient._transpile_to_supported_operations(circuit,
    > supported_gates)
    >      92         circuit = transpile(
    >      93             circuit, basis_gates=list(supported_gates), optimization_level=0
    >      94         )
    >      95     except Exception as exc:
    > ---> 96         raise QiskitError(
    >      97             f"Could not transpile the circuit provided {circuit} into supported gates "
    >      98             f"{supported_gates}."
    >      99         ) from exc
    >     100 return circuit
    > 
    > QiskitError: "Could not transpile the circuit provided (....QC) into supported gates {'rz', 'ry', 'y', 'u', 'h', 'z', 'x', 'cx', 'cz', 'p', 'rx', 'cy'}."

When experimenting with the Lab-4 case of the qiskit2021 summer machine learning school, the quantum circuit in the notebook of Lab-4 was replaced (the circuit is not convenient to provide), the structure is much more complicated than the provided case, and the following problems occur when compiling

Unable to map source basis {('h', 1), ('save_density_matrix', 3), ('swap', 2), ('ry', 1), ('ccx', 3), ('barrier', 18), ('cx', 2)} to target basis {'rz', 'ry', 'y', 'barrier', 'u', 'snapshot', 'h', 'z', 'measure', 'x', 'cx', 'delay', 'cz', 'reset', 'p', 'rx', 'cy'} over library

$\endgroup$
0

1 Answer 1

0
$\begingroup$

according to this line

TranspilerError: "Unable to map source basis {('h', 1),
    > ('save_density_matrix', 3), ('swap', 2), ('ry', 1), ('ccx', 3),
    > ('barrier', 18), ('cx', 2)} to target basis {'rz', 'ry', 'y',
    > 'barrier', 'u', 'snapshot', 'h', 'z', 'measure', 'x', 'cx', 'delay',
    > 'cz', 'reset', 'p', 'rx', 'cy'} over library
    > <qiskit.circuit.equivalence.EquivalenceLibrary object at
    > 0x000001D80DDAD310>."

it happen is because your source basis have save_density_matrix, you should add it to your supported_gates also. always check Error message to understand the reason.

$\endgroup$

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.