Closed Contextualist closed 2 years ago
Hi @Contextualist! I have also seen this error before, thanks for raising it! You can get it to work be calling .decompose()
on your final ansatz before returning from your custom VQECientUCCFactory
.
I will leave this issue open as this is likely something we should fix internally but the above workaround should make things work for you in the meantime. Let me know if this still does not help :+1:
Thanks for your prompt response, @mrossinek ! I tried to do the following edit for the VQEUCCFactory.get_solver
:
+ ansatz = ansatz.decompose()
vqe = VQEProgram(
ansatz=ansatz,
optimizer=self.optimizer,
However, I am still seeing the same error. Here is what the decomposed circuit looks like:
┌───┐ ┌─────┐ ┌───┐ ┌──────────────┐┌───┐ ┌───┐ ┌───────────────┐┌───────────────┐ ┌────────────┐ ┌─────┐┌───┐┌───┐┌──────────────┐┌───┐┌───┐ ┌───┐ »
q_0: ─────┤ X ├───────────┤ Sdg ├─────────┤ H ├────┤ Rz(2.0*t[0]) ├┤ H ├──────┤ S ├──────┤ circuit-36_dg ├┤ circuit-45_dg ├──┤ circuit-36 ├─┤ Sdg ├┤ H ├┤ X ├┤ Rz(1.0*t[2]) ├┤ X ├┤ H ├────┤ S ├─────»
┌────┴───┴─────┐┌────┴─────┴────┐┌───┴───┴───┐└───┬─────┬────┘├───┤┌─────┴───┴─────┐└─────┬───┬─────┘└─────┬───┬─────┘┌─┴────────────┴┐└┬───┬┘└───┘└─┬─┘└──────────────┘└─┬─┘├───┤┌───┴───┴────┐»
q_1: ┤ circuit-9_dg ├┤ circuit-18_dg ├┤ circuit-9 ├────┤ Sdg ├─────┤ H ├┤ Rz(-2.0*t[1]) ├──────┤ H ├────────────┤ S ├──────┤ circuit-89_dg ├─┤ H ├────────■────────────────────■──┤ H ├┤ circuit-89 ├»
└──────────────┘└───────────────┘└───────────┘ └─────┘ └───┘└───────────────┘ └───┘ └───┘ └───────────────┘ └───┘ └───┘└────────────┘»
« ┌───────────────┐┌───┐┌───┐┌───────────────┐┌───┐┌───┐┌────────────┐
«q_0: ┤ circuit-63_dg ├┤ H ├┤ X ├┤ Rz(-1.0*t[2]) ├┤ X ├┤ H ├┤ circuit-63 ├
« └────┬─────┬────┘├───┤└─┬─┘└───────────────┘└─┬─┘├───┤└───┬───┬────┘
«q_1: ─────┤ Sdg ├─────┤ H ├──■─────────────────────■──┤ H ├────┤ S ├─────
« └─────┘ └───┘ └───┘ └───┘
Right, sorry about that! What you actually need to do is to transpile the circuit with a subset of supported basis gates. I did something similar in a workshop whose notebook I posted as a Gist, here (cell 26). Basically you can try the following:
from qiskit import transpile
basis_gates = ["rx", "ry", "rz", "sx", "cx"]
transpiled_ansatz = transpile(ansatz, basis_gates=basis_gates, optimization_level=0)
I just tried it out. I can confirm that the basis gate transpilation workaround works. Thanks!
The source of it was Qiskit/qiskit-terra#7429, which still persists, but since Qiskit 0.33 the UCCSD ansatz uses the new PauliEvolutionGate
which doesn't construct a circuit with empty gates anymore. So in brief, this bug shouldn't exist anymore.
I tried it myself but, @Contextualist, would you mind trying with the latest Qiskit versions as well?
Thank you, @Cryoris ! I just tested with the following settings:
and the bug cannot be reproduced with the original setup
Environment
What is happening?
I tried to set up UCCSD ansatz to for
VQEProgram
, but the ansatz failed to be transpiled in the remote. In particular, I am seeing the following exception being returned:Full traceback from the remote runtime
``` Unable to retrieve job result. Job c6kq1hmgkavn0ge2re20 has failed: 2021-12-03T04:45:09.200181663Z /usr/local/lib/python3.8/site-packages/sympy/core/expr.py:2451: SymPyDeprecationWarning: 2021-12-03T04:45:09.200348792Z 2021-12-03T04:45:09.200524237Z expr_free_symbols method has been deprecated since SymPy 1.9. See 2021-12-03T04:45:09.200682015Z https://github.com/sympy/sympy/issues/21494 for more info. 2021-12-03T04:45:09.200831012Z 2021-12-03T04:45:09.200966077Z SymPyDeprecationWarning(feature="expr_free_symbols method", 2021-12-03T04:45:09.594976991Z concurrent.futures.process._RemoteTraceback: 2021-12-03T04:45:09.595027186Z """ 2021-12-03T04:45:09.595041516Z Traceback (most recent call last): 2021-12-03T04:45:09.595041516Z File "/usr/local/lib/python3.8/concurrent/futures/process.py", line 239, in _process_worker 2021-12-03T04:45:09.595041516Z r = call_item.fn(*call_item.args, **call_item.kwargs) 2021-12-03T04:45:09.595041516Z File "/usr/local/lib/python3.8/concurrent/futures/process.py", line 198, in _process_chunk 2021-12-03T04:45:09.595041516Z return [fn(*args) for args in chunk] 2021-12-03T04:45:09.595041516Z File "/usr/local/lib/python3.8/concurrent/futures/process.py", line 198, inHow can we reproduce the issue?
Here's my main setup (click to expand)
```python from qiskit_nature.drivers import Molecule from qiskit_nature.drivers.second_quantization import PSI4Driver molecule = Molecule(geometry= [['H', [0., 0., 0.]], ['H', [0., 0., 0.735]]], charge=0, multiplicity=1) basis = "sto-3g" driver = PSI4Driver.from_molecule(molecule=molecule, basis=basis) from qiskit.utils import QuantumInstance from qiskit import IBMQ IBMQ.load_account() provider = IBMQ.get_provider(group='open') backend = provider.get_backend("ibmq_qasm_simulator") qins = QuantumInstance( backend=backend, shots=1024, optimization_level=2, ) # VQEClientUCCFactory is adapted from VQEUCCFactory; see below solver = VQEClientUCCFactory( quantum_instance=qins, provider=provider, optimizer=dict( name="QN-SPSA", maxiter=100, resamplings={1: 100}, ), measurement_error_mitigation=True, ) def solve(driver, solver): from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem problem = ElectronicStructureProblem(driver) from qiskit_nature.mappers.second_quantization import ParityMapper from qiskit_nature.converters.second_quantization import QubitConverter mapper = ParityMapper() converter = QubitConverter(mapper=mapper, two_qubit_reduction=True) from qiskit_nature.algorithms import GroundStateEigensolver calc = GroundStateEigensolver(converter, solver) r = calc.solve(problem) return r.total_energies[0], if __name__ == "__main__": print(solve(driver, solver)) ```The
VQEClientUCCFactory
mentioned in the code above is a copy ofVQEUCCFactory
with methodget_solver
modifiedhttps://github.com/Qiskit/qiskit-nature/blob/8d2b0eb1606620ed45211653ed20ab78335a39bc/qiskit_nature/algorithms/ground_state_solvers/minimum_eigensolver_factories/vqe_ucc_factory.py#L187-L233
the
VQE
constructor part ofVQEUCCFactory.get_solver
is changed to:What should happen?
It should run and return the final total energy.
Any suggestions?
Not sure why there is a gate named
circuit-36_dg
found during the transpilation (see the exception above).