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

55 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2023-07-05 18:29:11 +00:00
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.](https://covalent.readthedocs.io/en/latest/index.html)
---
# 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:
```python
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)
```