Dear PennyLane team,
Hope all is well.
I’m having problems with using ApproxTimeEvolution
.
I would like to simulate a simple Hamiltonian given by HH molecule using ApproxTimeEvolution
operator. However, the resulting circuit has a number of issues:
- It seems the circuit contains both the operator
ApproxTimeEvolution
and its decomposition. Having just a containerApproxTimeEvolution
doesn’t make any sense so I attempt to decompose it. However, this produces a weird result (see the figure). - When I export the circuit to QASM, the PauliRotation gates are decomposed into CNOTS, and single-qubit rotation. This is undesired behavior as I did not specify that the circuit should be decomposed into single- and two-qubit gates.
Here is the code to reproduce the issue:
symbols = ["H", "H"]
coordinates = np.array([0, 0, 0, 0, 0, 0.74137727])
hamiltonian, num_qubits = qchem.molecular_hamiltonian(symbols, coordinates, method="pyscf")
print(f"Number of qubits: {num_qubits}")
print("Qubit Hamiltonian")
print(hamiltonian)
wires = range(num_qubits)
num_wires = num_qubits
dev = qml.device('default.qubit', wires=wires)
evolution_time=0.5
trotter_steps=1
@qml.qnode(dev)
def circuit(evolution_time):
ApproxTimeEvolution(hamiltonian, evolution_time, trotter_steps).decompose()
return [qml.expval(qml.PauliZ(wires=i)) for i in wires]
specs_func = qml.specs(circuit, expansion_strategy='device')
print(specs_func(evolution_time))
fig, ax = qml.draw_mpl(circuit)(evolution_time)
Output of spec_func
:
{'gate_sizes': defaultdict(<class 'int'>, {1: 8, 2: 12, 4: 8}), 'gate_types': defaultdict(<class 'int'>, {'PauliRot': 28}), 'num_operations': 28, 'num_observables': 4, 'num_diagonalizing_gates': 0, 'num_used_wires': 4, 'depth': 19, 'num_trainable_params': 28, 'num_device_wires': 4, 'device_name': 'default.qubit.autograd', 'expansion_strategy': 'gradient', 'gradient_options': {}, 'interface': 'autograd', 'diff_method': 'best', 'gradient_fn': 'backprop'}
Note that there is a wrong number of Pauli rotation gates (twice of what is expected). There should be 14 Pauli rotation gates because there are 14 non-tirival Hamiltonian terms.
The drawing of the circuit shows that the circuit contains both the decomposition and the original ApproxTimeEvo operator which is also incorrect.
Name: PennyLane
Version: 0.28.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author:
Author-email:
License: Apache License 2.0
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, retworkx, scipy, semantic-version, toml
Required-by: PennyLane-Lightning
Platform info: Linux-5.19.0-46-generic-x86_64-with-glibc2.35
Python version: 3.10.6
Numpy version: 1.23.5
Scipy version: 1.10.0
Thank you!