Notepad/enter/Machine Tips (Quantum)/Resources/Code & Circuit Operations/Languages/Python Libraries/Covalent.md

1.1 KiB

Covalent is meant to be a pythonic workflow to streamline all of those quantum libraries we have listed here. !Pasted image 20221218215831.png You can read the in-depth docs here.


Get Started!

To start we run:

pip3 install covalent

Then we start the covalent server by running:

$ covalent start
Covalent server has started at http://localhost:48008

We can then run a workflow for instance:

import covalent as ct

# Construct manageable tasks out of functions
# by adding the @covalent.electron decorator
@ct.electron
def add(x, y):
   return x + y

@ct.electron
def multiply(x, y):
   return x*y

@ct.electron
def divide(x, y):
   return x/y

# Construct the workflow by stitching together
# the electrons defined earlier in a function with
# the @covalqqqqdcdent.lattice decorator
@ct.lattice
def workflow(x, y):
   r1 = add(x, y)
   r2 = [multiply(r1, y) for _ in range(4)]
   r3 = [divide(x, value) for value in r2]
   return r3

# Dispatch the workflow
dispatch_id = ct.dispatch(workflow)(1, 2)
result = ct.get_result(dispatch_id)
print(result)