Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimization_level=3 triggers error in unrolling #2349

Closed
1ucian0 opened this issue May 8, 2019 · 2 comments · Fixed by #2357
Closed

optimization_level=3 triggers error in unrolling #2349

1ucian0 opened this issue May 8, 2019 · 2 comments · Fixed by #2357
Assignees
Labels
bug Something isn't working status: pending PR It has one or more PRs pending to solve this issue

Comments

@1ucian0
Copy link
Member

1ucian0 commented May 8, 2019

Originally posted by @itoko in #2339 (comment)

The follow input triggers and an issue in the unroller.

from qiskit import QuantumCircuit, QuantumRegister, QiskitError
from qiskit.compiler import transpile
from qiskit.transpiler import CouplingMap
q = QuantumRegister(2)
qc = QuantumCircuit(q)
qc.cx(q[0], q[1])
qc.cx(q[0], q[1])
coupling = CouplingMap([[0, 1]])
compiled = transpile(qc, coupling_map=CouplingMap([[0, 1]]), optimization_level=3)
print(compiled)
QiskitError: "Cannot unroll the circuit to the given basis, ['cx', 'cx']. No rule to expand instruction U."
@1ucian0 1ucian0 self-assigned this May 8, 2019
@1ucian0 1ucian0 added this to the 0.8.1 milestone May 8, 2019
@1ucian0 1ucian0 added the bug Something isn't working label May 8, 2019
@1ucian0 1ucian0 added the status: pending PR It has one or more PRs pending to solve this issue label May 8, 2019
mtreinish pushed a commit to mtreinish/qiskit-core that referenced this issue May 9, 2019
…2357)

Fixes Qiskit#2349

When a basis is not defined for a circuit, the default basis set is the
set of gates used in the circuit. This makes total sense to me.

However, passes might add gates and the might be out of that bases. For
this reason, I'm suggesting to add the base basis (UBase and CXBase) as
part of the default basis set. If I understand correctly, the base
basis (is that their name?) is supported by every backend by
definition, so the gates that are added by the transpiler can run in
the backend.

(cherry picked from commit 4bfcc5d)
1ucian0 pushed a commit that referenced this issue May 10, 2019
…2386)

Fixes #2349

When a basis is not defined for a circuit, the default basis set is the
set of gates used in the circuit. This makes total sense to me.

However, passes might add gates and the might be out of that bases. For
this reason, I'm suggesting to add the base basis (UBase and CXBase) as
part of the default basis set. If I understand correctly, the base
basis (is that their name?) is supported by every backend by
definition, so the gates that are added by the transpiler can run in
the backend.

(cherry picked from commit 4bfcc5d)
@sassan72
Copy link

I encountered the same error. QiskitError: 'Cannot unroll the circuit to the given basis, method. No rule to expand instruction ry.'

QiskitError Traceback (most recent call last)
in
13 #g, g_bias = zip(*Parallel(n_jobs=-2)(delayed(gradients)(var_corrected, feats_train_batch[j], Y_train_batch[j], bias_corrected) for j in range(batch_size) ))
14 for j in range(batch_size):
---> 15 g, g_bias = gradients(var_corrected, feats_train_batch[j], Y_train_batch[j], bias_corrected)
16 grads += g / batch_size
17 grad_bias +=g_bias / batch_size

in gradients(params, feature, label, bias)
77 grads[i][j][2] = 0.5 * (imaginary(params, params_bis, feature) - imag)
78 params_bis[i][j][2]-=np.pi
---> 79 p = execute_circuit(params, feature, bias=bias)
80 grad_bias = (p - label) / (p * (1 - p))
81 grads *= grad_bias

in execute_circuit(params, feature, bias)
58 circuit = create_circuit(params, circuit, [0,1,2,3])
59 circuit.measure(0,c)
---> 60 result = execute(circuit,backend, backend_options).result()
61
62 counts = result.get_counts(circuit)

/opt/anaconda3/lib/python3.7/site-packages/qiskit/execute.py 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, schedule_los, meas_level, meas_return, memory_slots, memory_slot_size, rep_time, parameter_binds, schedule_circuit, inst_map, meas_map, scheduling_method, **run_config)
249 seed_transpiler=seed_transpiler,
250 optimization_level=optimization_level,
--> 251 backend=backend)
252
253 if schedule_circuit:

/opt/anaconda3/lib/python3.7/site-packages/qiskit/compiler/transpile.py in transpile(circuits, backend, basis_gates, coupling_map, backend_properties, initial_layout, layout_method, routing_method, seed_transpiler, optimization_level, pass_manager, callback, output_name)
208
209 # Transpile circuits in parallel
--> 210 circuits = parallel_map(_transpile_circuit, list(zip(circuits, transpile_args)))
211
212 if len(circuits) == 1:

/opt/anaconda3/lib/python3.7/site-packages/qiskit/tools/parallel.py in parallel_map(task, values, task_args, task_kwargs, num_processes)
103 """
104 if len(values) == 1:
--> 105 return [task(values[0], *task_args, **task_kwargs)]
106
107 Publisher().publish("terra.parallel.start", len(values))

/opt/anaconda3/lib/python3.7/site-packages/qiskit/compiler/transpile.py in _transpile_circuit(circuit_config_tuple)
305
306 return pass_manager.run(circuit, callback=transpile_config['callback'],
--> 307 output_name=transpile_config['output_name'])
308
309

/opt/anaconda3/lib/python3.7/site-packages/qiskit/transpiler/passmanager.py in run(self, circuits, output_name, callback)
212 """
213 if isinstance(circuits, QuantumCircuit):
--> 214 return self._run_single_circuit(circuits, output_name, callback)
215 elif len(circuits) == 1:
216 return self._run_single_circuit(circuits[0], output_name, callback)

/opt/anaconda3/lib/python3.7/site-packages/qiskit/transpiler/passmanager.py in _run_single_circuit(self, circuit, output_name, callback)
275 if callback is None and self.callback: # TODO to remove with init(callback)
276 callback = self.callback
--> 277 result = running_passmanager.run(circuit, output_name=output_name, callback=callback)
278 self.property_set = running_passmanager.property_set
279 return result

/opt/anaconda3/lib/python3.7/site-packages/qiskit/transpiler/runningpassmanager.py in run(failed resolving arguments)
113 for passset in self.working_list:
114 for pass_ in passset:
--> 115 dag = self.do_pass(pass, dag, passset.options)
116
117 circuit = dag_to_circuit(dag)

/opt/anaconda3/lib/python3.7/site-packages/qiskit/transpiler/runningpassmanager.py in do_pass(self, pass, dag, options)
143 # Run the pass itself, if not already run
144 if pass_ not in self.valid_passes:
--> 145 dag = self.run_this_pass(pass, dag)
146
147 # update the valid_passes property

/opt/anaconda3/lib/python3.7/site-packages/qiskit/transpiler/runningpassmanager.py in run_this_pass(self, pass, dag)
155 # Measure time if we have a callback or logging set
156 start_time = time()
--> 157 new_dag = pass_.run(dag)
158 end_time = time()
159 run_time = end_time - start_time

/opt/anaconda3/lib/python3.7/site-packages/qiskit/transpiler/passes/basis/unroller.py in run(self, dag)
95 raise QiskitError("Cannot unroll the circuit to the given basis, %s. "
96 "No rule to expand instruction %s." %
---> 97 (str(self.basis), node.op.name))
98
99 # hacky way to build a dag on the same register as the rule is defined

QiskitError: 'Cannot unroll the circuit to the given basis, method. No rule to expand instruction ry.'

@kdk
Copy link
Member

kdk commented Jul 14, 2020

Hi @sassan72 , this sounds like a separate issue (that is triggering the same error). Can you open a new issue with your python version, qiskit version, and some example code that replicates the error you're seeing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status: pending PR It has one or more PRs pending to solve this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants