Skip to content

Commit 5d4bbcf

Browse files
Sync docs for SDK version 0.95.0
1 parent f61a8ce commit 5d4bbcf

25 files changed

+1117
-1156
lines changed

.internal/docs/qmod-reference/language-reference/classical-types.md

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ In Qmod, scalar types represent numeric values, Boolean values, and Pauli base e
2121

2222
### Syntax
2323

24-
=== "Native"
25-
26-
- `int` represents integers
27-
- `real` represents real numbers (using floating point encoding)
28-
- `bool` represents the Boolean values `false` and `true`
29-
- `Pauli` represents the Pauli base elements using the symbols `Pauli::I`, `Pauli::X`, `Pauli::Y`, and `Pauli::Z` (with the integer values 0, 1, 2, 3 respectively)
30-
3124
=== "Python"
3225

3326
Python Classes are used to represent scalar types
@@ -37,22 +30,29 @@ In Qmod, scalar types represent numeric values, Boolean values, and Pauli base e
3730
- `CBool` represents the Boolean values `False` and `True`
3831
- `Pauli` represents the Pauli base elements using the symbols `Pauli.I`, `Pauli.X`, `Pauli.Y`, and `Pauli.Z` (with the integer values 0, 1, 2, 3 respectively)
3932

33+
=== "Native"
34+
35+
- `int` represents integers
36+
- `real` represents real numbers (using floating point encoding)
37+
- `bool` represents the Boolean values `false` and `true`
38+
- `Pauli` represents the Pauli base elements using the symbols `Pauli::I`, `Pauli::X`, `Pauli::Y`, and `Pauli::Z` (with the integer values 0, 1, 2, 3 respectively)
39+
4040
## Arrays
4141

4242
Arrays are homogenous collections of scalars or structs with random access.
4343

4444
### Syntax
4545

46-
=== "Native"
47-
48-
Array types have the form - _element-type_ **[** [ _length_expression_ ] **]**
49-
5046
=== "Python"
5147

5248
Array types are represented with the generic class `CArray`. Arguments are declared with the type hint in the form:
5349

5450
_name_ **:** **CArray** [ **[** _element-type_ [ **,** _length_expression_ ] **]** ]
5551

52+
=== "Native"
53+
54+
Array types have the form - _element-type_ **[** [ _length_expression_ ] **]**
55+
5656
### Semantics
5757

5858
_element-type_ is any scalar, array, or struct type.
@@ -75,6 +75,24 @@ takes an array of reals, and uses the `.len` attribute and array subscripting to
7575
the elements of the array. Note that index -1 signifies the last element in an array
7676
(similar to Python).
7777

78+
=== "Python"
79+
80+
```python
81+
from classiq import qfunc, CArray, CReal, QBit, RX, allocate, if_
82+
83+
84+
@qfunc
85+
def foo(arr: CArray[CReal], qb: QBit) -> None:
86+
if_(arr.len > 2, lambda: RX(arr[-1], qb), lambda: RX(arr[0], qb))
87+
88+
89+
@qfunc
90+
def main() -> None:
91+
q0 = QBit()
92+
allocate(q0)
93+
foo([0.5, 1.0, 1.5], q0)
94+
```
95+
7896
=== "Native"
7997

8098
```
@@ -93,27 +111,17 @@ the elements of the array. Note that index -1 signifies the last element in an a
93111
}
94112
```
95113

96-
=== "Python"
97-
98-
```python
99-
from classiq import qfunc, CArray, CReal, QBit, RX, allocate, if_
100-
101-
102-
@qfunc
103-
def foo(arr: CArray[CReal], qb: QBit) -> None:
104-
if_(arr.len > 2, lambda: RX(arr[-1], qb), lambda: RX(arr[0], qb))
114+
## Structs
105115

116+
Structs are aggregates of variables, called _fields_, each with its own name and type.
106117

107-
@qfunc
108-
def main() -> None:
109-
q0 = QBit()
110-
allocate(q0)
111-
foo([0.5, 1.0, 1.5], q0)
112-
```
118+
=== "Python"
113119

114-
## Structs
120+
A Qmod classical struct is defined with a Python data class: A class decorated with
121+
`@dataclasses.dataclass`.
115122

116-
Structs are aggregates of variables, called _fields_, each with its own name and type.
123+
Fields need to be declared with type-hints like classical arguments of functions.
124+
Fields are initialized and accessed like attributes of Python object.
117125

118126
=== "Native"
119127

@@ -126,45 +134,12 @@ Structs are aggregates of variables, called _fields_, each with its own name and
126134
_field-value-list_ is a list of zero or more comma-separated field initializations in the form -
127135
_name_ **=** _expression_.
128136

129-
=== "Python"
130-
131-
A Qmod classical struct is defined with a Python data class: A class decorated with
132-
`@dataclasses.dataclass`.
133-
134-
Fields need to be declared with type-hints like classical arguments of functions.
135-
Fields are initialized and accessed like attributes of Python object.
136-
137137
### Example
138138

139139
In the following example a struct type called `MyStruct` is defined. Function `foo`
140140
takes an argument of this type and accesses its fields. Function `main` instantiates
141141
and populates `MyStruct` in its call to `foo`.
142142

143-
=== "Native"
144-
145-
```
146-
struct MyStruct {
147-
loop_counts: int[];
148-
angle: real;
149-
}
150-
151-
qfunc foo(ms: MyStruct, qv: qbit[2]) {
152-
H(qv[0]);
153-
repeat (index: ms.loop_counts[1]) {
154-
PHASE(ms.angle + 0.5, qv[1]);
155-
}
156-
}
157-
158-
qfunc main() {
159-
qba: qbit[];
160-
allocate(2, qba);
161-
foo(MyStruct {
162-
loop_counts = [1, 2],
163-
angle = 0.1
164-
}, qba);
165-
}
166-
```
167-
168143
=== "Python"
169144

170145
```python
@@ -194,6 +169,31 @@ and populates `MyStruct` in its call to `foo`.
194169
foo(MyStruct(loop_counts=[1, 2], angle=0.1), qba)
195170
```
196171

172+
=== "Native"
173+
174+
```
175+
struct MyStruct {
176+
loop_counts: int[];
177+
angle: real;
178+
}
179+
180+
qfunc foo(ms: MyStruct, qv: qbit[2]) {
181+
H(qv[0]);
182+
repeat (index: ms.loop_counts[1]) {
183+
PHASE(ms.angle + 0.5, qv[1]);
184+
}
185+
}
186+
187+
qfunc main() {
188+
qba: qbit[];
189+
allocate(2, qba);
190+
foo(MyStruct {
191+
loop_counts = [1, 2],
192+
angle = 0.1
193+
}, qba);
194+
}
195+
```
196+
197197
## Hamiltonians
198198

199199
Qmod's Python embedding offers a specialized syntax for creating

.internal/docs/qmod-reference/language-reference/functions.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ The following example demonstrates how to define a simple Qmod function. Functio
1414
declares and uses a classical real-number parameter `p` and a quantum single-qubit
1515
parameter `q`.
1616

17-
=== "Native"
18-
19-
```
20-
qfunc rotate(p: real, q: qbit) {
21-
PHASE(p * pi, q);
22-
}
23-
```
24-
2517
=== "Python"
2618

2719
```python
@@ -34,23 +26,20 @@ parameter `q`.
3426
PHASE(theta=p * pi, target=qv)
3527
```
3628

29+
=== "Native"
30+
31+
```
32+
qfunc rotate(p: real, q: qbit) {
33+
PHASE(p * pi, q);
34+
}
35+
```
36+
3737
## Syntax
3838

3939
The signature of a function comprises the function's name and its parameters, that is,
4040
the arguments it expects when called. The function's body is the description of its
4141
implementation as a sequence of statements.
4242

43-
=== "Native"
44-
45-
(**qfunc** | **qperm**) _name_ **(** _parameters_ **)** **{** _statements_ **}**
46-
47-
_parameters_ is a list of zero or more comma-separated declarations in one of the
48-
three forms:
49-
50-
- \[ **output** | **input** \] \[ **const** \] _name_ **:** _quantum-type_
51-
- _name_ **:** _classical-type_
52-
- _name_ **:** (**qfunc** | **qperm**) [ **[** **]** ] **(** _parameters_ **)**
53-
5443
=== "Python"
5544

5645
A quantum function is defined with a regular Python function decorated with `@qfunc`
@@ -65,6 +54,17 @@ implementation as a sequence of statements.
6554
`Input` and `Output`. The _const_ modifier for quantum arguments
6655
is represented with the generic class `Const`.
6756

57+
=== "Native"
58+
59+
(**qfunc** | **qperm**) _name_ **(** _parameters_ **)** **{** _statements_ **}**
60+
61+
_parameters_ is a list of zero or more comma-separated declarations in one of the
62+
three forms:
63+
64+
- \[ **output** | **input** \] \[ **const** \] _name_ **:** _quantum-type_
65+
- _name_ **:** _classical-type_
66+
- _name_ **:** (**qfunc** | **qperm**) [ **[** **]** ] **(** _parameters_ **)**
67+
6868
## Semantics
6969

7070
- A function definition introduces a new function symbol into the global namespace.
@@ -104,18 +104,6 @@ Statements can do one of the following:
104104

105105
The following example demonstrates function declarations:
106106

107-
=== "Native"
108-
109-
```
110-
qfunc foo(n: int, qba: qbit[2*n]) {
111-
// ...
112-
}
113-
114-
qfunc bar(x: qnum, y: qnum, output res: qnum) {
115-
// ...
116-
}
117-
```
118-
119107
=== "Python"
120108

121109
```python
@@ -132,6 +120,18 @@ The following example demonstrates function declarations:
132120
pass
133121
```
134122

123+
=== "Native"
124+
125+
```
126+
qfunc foo(n: int, qba: qbit[2*n]) {
127+
// ...
128+
}
129+
130+
qfunc bar(x: qnum, y: qnum, output res: qnum) {
131+
// ...
132+
}
133+
```
134+
135135
Note that when classical arguments are used to specify subsequent arguments, as in the
136136
case where `qba` is a qubit array of size 2*n, the expression is specified as a string
137137
literal because the Python variable `n` is not in scope.
@@ -143,17 +143,6 @@ built-in function `H()` and then iteratively function `PHASE()` using the _repea
143143
statement (for more on `repeat` see
144144
[Classical Control Flow](statements/classical-control-flow.md)).
145145

146-
=== "Native"
147-
148-
```
149-
qfunc foo(n: int, qv: qbit) {
150-
H(qv);
151-
repeat (index: n) {
152-
PHASE((index / n) * pi, qv);
153-
}
154-
}
155-
```
156-
157146
=== "Python"
158147

159148
A function decorated with `@qfunc` is executed by the Python interpreter to construct
@@ -170,3 +159,14 @@ statement (for more on `repeat` see
170159
H(qv)
171160
repeat(n, lambda i: PHASE(theta=(i / n) * pi, target=qv))
172161
```
162+
163+
=== "Native"
164+
165+
```
166+
qfunc foo(n: int, qv: qbit) {
167+
H(qv);
168+
repeat (index: n) {
169+
PHASE((index / n) * pi, qv);
170+
}
171+
}
172+
```

0 commit comments

Comments
 (0)