# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: kongsr-rdkit
#     language: python
#     name: kongsr-rdkit
# ---

# +
import pennylane as qml
from qiskit import IBMQ
import time

dev = qml.device('qiskit.ibmq', wires=8, backend='ibmq_16_melbourne')
@qml.qnode(dev, interface='torch')
def gen_circuit(w):
    # random noise as generator input
    z1 = random.uniform(-1, 1)
    z2 = random.uniform(-1, 1)
    layers = 1
    qubits = 8
    
    # construct generator circuit for both atom vector and node matrix
    for i in range(qubits):
        qml.RY(np.arcsin(z1), wires=i)
        qml.RZ(np.arcsin(z2), wires=i)
    for l in range(layers):
        for i in range(qubits):
            qml.RY(w[i], wires=i)
#             qml.Hadamard(wires=i)
        for i in range(qubits-1):
            qml.CNOT(wires=[i, i+1])
            qml.RZ(w[i+qubits], wires=i+1)
            qml.CNOT(wires=[i, i+1])
#     for i in range(qubits):
#         qml.Hadamard(wires=i)
    return [qml.expval(qml.PauliZ(i)) for i in range(qubits)]
# -



circuit(0.2, 0.1, 0.3)

for i in range(5):
    t0 = time.time()
    print(circuit(0.2+i*0.1, 0.1-i*0.1, 0.3+i*0.01))
    print("Time elapsed: ", time.time()-t0)



StarcoderdataJupyterScriptsDedupFiltered