Last active
July 26, 2022 13:47
-
-
Save scottwn/29eb54fc436ed72b90c44b33bd004408 to your computer and use it in GitHub Desktop.
Minimal example of Covalent integration with Qiskit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qiskit import QuantumCircuit, Aer | |
import qiskit | |
import covalent as ct | |
@ct.electron | |
def hadamard(circuit, qubit): | |
circuit.h(qubit) | |
return circuit | |
@ct.electron | |
def save_statevector(circuit, backend): | |
circuit.save_statevector() | |
return circuit | |
@ct.electron | |
@ct.lattice | |
def my_circuit(qubits, backend): | |
qc = QuantumCircuit(qubits) | |
for i in range(0, qubits): | |
qc = hadamard(qc, i) | |
qc = save_statevector(qc, backend) | |
return qc | |
@ct.electron | |
def assemble(circuit): | |
return qiskit.assemble(circuit) | |
@ct.electron | |
def get_statevector(qobj, backend): | |
return backend.run(qobj).result().get_statevector() | |
@ct.lattice | |
def get_state(qubits, backend): | |
qc = my_circuit(qubits, backend) | |
qobj = assemble(qc) | |
state = get_statevector(qobj, backend) | |
return state | |
sim = Aer.get_backend("aer_simulator") | |
ct.dispatch(get_state)(2, sim) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment