Skip to content

Commit

Permalink
improve README example with @blakejohnson suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
caryan committed Apr 13, 2017
1 parent f0a6327 commit 1e7764f
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,31 @@ measurement results to variables and control flow statements.

```python
# single qubit reset
from qgl2.qgl2 import QRegister
from qgl2.qgl2 import qgl2decl, QRegister
from qgl2.qgl1 import Id, X, MEAS
q = QRegister(1)
m = MEAS(q)
if m:
X(q)
else:
Id(q)

@qgl2decl
def reset():
q = QRegister(1)
m = MEAS(q)
if m:
X(q)
else:
Id(q)
```

Once a function is decorated with `@qgl2decl` it can act as the `main` for
compiling a QGL2 program. If the `reset` function is placed in Python module
then it can be compiled with:

```python
from pyqgl2.main import compile_function
result = compile_function(filename, "reset")
```

With decorators and type annotations, function calls that execute pulses on
qubits make it possible to write tidy compact code using natural pythonic
iteration tools.
QGL2 uses type annotations in function calls to mark quantum and classical
values. Encapsulating subroutines makes it possible to write tidy compact code
using natural pythonic iteration tools.

```python
# multi-qubit QFT
Expand Down

0 comments on commit 1e7764f

Please sign in to comment.