Hello Pennylane Team
This is my first post on the messageboard.
The following code does not yield any actual results on measurement. I am unsure if there is something else required in code to obtain a proper measurement or if perhaps the amplitude embedding method is incompatible with this circuit Ansatz.
Any help or comments would be welcome.
Many thanks
Berend
'''
DNA encoder using complex amplitudes to represent nucleotide bases
followed by variational quantum circuit.
Cost function not yet implemented.
'''
import pennylane as qml
from pennylane import numpy as np
seq='ATTGTCGGTT'
DNA_list=list(seq)
i=0
while True:
if 2**i>=len(seq):
n=i
break
i+=1
print(n, 2**n)
encode_DNA={'A':'-1','C':'1','G':'-1j','T':'1j'}
encoded_seq=[complex(encode_DNA[base]) for base in DNA_list]
''' variational quantum circuit
the circuit uses alternating RQ and RX gates and entangling CNOT gates
'''
def circuit(encoded_seq, qubits,layers, phi):
qml.AmplitudeEmbedding(features=encoded_seq, wires=range(qubits), normalize=True, pad_with=0.)
for l in range(layers):
for q in range(qubits):
# alternating Ry and Rz gates
if q%2!=0: #odd gate
qml.RZ(phi[q,l], wires=q)
else:
qml.RY(phi[q,l], wires=q)
for q in range(qubits-1):
# entangling layer - connect neighbouring wires and the last and first one
qml.CNOT(wires=[q,q+1])
qml.CNOT(wires=[qubits,0])
# Expectation values in the Z basis
exp_vals = [qml.expval(qml.PauliZ(q)) for q in range(qubits)]
return exp_vals
qubits=4
layers=4
phi=np.random.random(size =(qubits, layers))
results=circuit(encoded_seq,qubits,layers,phi)
print(results)
fig, ax=qml.draw_mpl(circuit)(encoded_seq,qubits,layers,phi)
fig.show()
It runs but does not provide any measurement results:
[expval(PauliZ(wires=[0])), expval(PauliZ(wires=[1])), expval(PauliZ(wires=[2])), expval(PauliZ(wires=[3]))]
# Put full error message here
Name: PennyLane
Version: 0.32.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: GitHub - PennyLaneAI/pennylane: PennyLane is a cross-platform Python library for differentiable programming of quantum computers. Train a quantum computer the same way as a neural network.
Author:
Author-email:
License: Apache License 2.0
Location: /Users/brah/anaconda3/envs/Pennylane_test/lib/python3.8/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning
Platform info: macOS-12.6.3-arm64-arm-64bit
Python version: 3.8.18
Numpy version: 1.24.3
Scipy version: 1.10.1
Installed devices:
- default.gaussian (PennyLane-0.32.0)
- default.mixed (PennyLane-0.32.0)
- default.qubit (PennyLane-0.32.0)
- default.qubit.autograd (PennyLane-0.32.0)
- default.qubit.jax (PennyLane-0.32.0)
- default.qubit.tf (PennyLane-0.32.0)
- default.qubit.torch (PennyLane-0.32.0)
- default.qutrit (PennyLane-0.32.0)
- null.qubit (PennyLane-0.32.0)
- lightning.qubit (PennyLane-Lightning-0.32.0)