Skip to content

Commit 51d2e10

Browse files
committed
Merge branch 'main' of https://github.com/OpenQuantumDesign/oqd-core into visualization
1 parent cbe646a commit 51d2e10

File tree

8 files changed

+156
-101
lines changed

8 files changed

+156
-101
lines changed

docs/explanation/atomic_interface.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,25 @@ microwave_pulse = Pulse(
212212

213213
///
214214

215+
#### Measurement
216+
217+
To perform a measurement, we not only have to turn on an optical channel, we also have to turn on a detector, this is handled by the [`MeasurePulse`][oqd_core.interface.atomic.protocol.MeasurePulse].
218+
219+
<!-- prettier-ignore -->
220+
/// admonition | Example
221+
type: example
222+
223+
Pulse that drives a fluorescent transition and turns on the detector for a duration $T$:
224+
225+
```python
226+
detection_pulse = MeasurePulse(
227+
beam=detection_beam,
228+
duration=T,
229+
)
230+
```
231+
232+
///
233+
215234
### Composition of Protocols
216235

217236
The pulse program for a quantum experiment is usually more complex than a pulse of a single beam. This is handled with [`SequentialProtocol`][oqd_core.interface.atomic.protocol.SequentialProtocol] and [`ParallelProtocol`][oqd_core.interface.atomic.protocol.ParallelProtocol].

docs/explanation/math_interface.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ The compatible operators for the math interface consist of:
101101
The compatible named functions include:
102102

103103
- trigonometric (`sin`, `cos`, `tan`)
104+
- inverse trigonometric functions (`asin`, `acos`, `atan`, `atan2`)
104105
- hyperbolic trigonometric (`sinh`, `cosh`, `tanh`)
106+
- inverse hyperbolic trigonometric functions (`asinh`, `acosh`, `atanh`)
105107
- exponential (`exp`)
106108
- logarithm (`log`)
109+
- complex number functions (`real`, `imag`, `conj`, `abs`)
110+
- step function (`heaviside`)
107111

108112
///
109113

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,10 @@ select = ["E4", "E7", "E9", "F", "I"]
6262
fixable = ["ALL"]
6363

6464
[tool.uv.sources]
65-
oqd-compiler-infrastructure = { git = "https://github.com/openquantumdesign/oqd-compiler-infrastructure", rev = "fix_conversion_rule" }
65+
oqd-compiler-infrastructure = { git = "https://github.com/openquantumdesign/oqd-compiler-infrastructure" }
6666

6767
[dependency-groups]
68-
dev = [
69-
"jupyter>=1.1.1",
70-
"pre-commit>=4.1.0",
71-
]
68+
dev = ["jupyter>=1.1.1", "pre-commit>=4.1.0"]
7269

7370

7471
[project.urls]

src/oqd_core/compiler/analog/passes/canonicalize.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PauliAlgebra,
2424
ProperOrder,
2525
PruneIdentity,
26+
PruneZeros,
2627
ScaleTerms,
2728
SortedOrder,
2829
)
@@ -119,5 +120,5 @@ def analog_operator_canonicalization(model):
119120
FixedPoint(scale_terms_chain),
120121
FixedPoint(Post(SortedOrder())),
121122
canonicalize_math_expr,
122-
verify_canonicalization,
123+
FixedPoint(Post(PruneZeros())),
123124
)(model=model)

src/oqd_core/compiler/analog/rewrite/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
PauliAlgebra,
2222
ProperOrder,
2323
PruneIdentity,
24+
PruneZeros,
2425
ScaleTerms,
2526
SortedOrder,
2627
)
@@ -36,4 +37,5 @@
3637
"ProperOrder",
3738
"ScaleTerms",
3839
"SortedOrder",
40+
"PruneZeros",
3941
]

src/oqd_core/compiler/analog/rewrite/canonicalize.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from oqd_compiler_infrastructure import RewriteRule
1818

19-
########################################################################################
2019
from oqd_core.compiler.analog.passes.analysis import analysis_term_index
2120
from oqd_core.interface.analog import (
2221
Annihilation,
@@ -49,6 +48,7 @@
4948
"ProperOrder",
5049
"ScaleTerms",
5150
"SortedOrder",
51+
"PruneZeros",
5252
]
5353

5454
########################################################################################
@@ -499,3 +499,33 @@ def map_OperatorAdd(self, model: OperatorAdd):
499499

500500
elif term1 < term2:
501501
return OperatorAdd(op1=model.op1, op2=model.op2)
502+
503+
504+
class PruneZeros(RewriteRule):
505+
"""
506+
Removes operators multiplied by zero
507+
508+
Args:
509+
model (VisitableBaseModel):
510+
511+
Returns:
512+
model (VisitableBaseModel):
513+
514+
Assumptions:
515+
[`GatherMathExpr`][oqd_core.compiler.analog.rewrite.canonicalize.GatherMathExpr],
516+
[`OperatorDistribute`][oqd_core.compiler.analog.rewrite.canonicalize.OperatorDistribute],
517+
[`ProperOrder`][oqd_core.compiler.analog.rewrite.canonicalize.ProperOrder],
518+
[`GatherPauli`][oqd_core.compiler.analog.rewrite.canonicalize.GatherPauli],
519+
[`NormalOrder`][oqd_core.compiler.analog.rewrite.canonicalize.NormalOrder]
520+
[`PruneIdentity`][oqd_core.compiler.analog.rewrite.canonicalize.PruneIdentity]
521+
522+
"""
523+
524+
def map_OperatorAdd(self, model):
525+
if isinstance(model.op1, OperatorScalarMul) and model.op1.expr == MathNum(
526+
value=0
527+
):
528+
return model.op2
529+
530+
if model.op2.expr == MathNum(value=0):
531+
return model.op1

src/oqd_core/interface/analog/operator.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def __sub__(self, other):
7474
return OperatorSub(op1=self, op2=other)
7575

7676
def __matmul__(self, other):
77-
if isinstance(other, MathExpr):
78-
raise TypeError(
79-
"Tried Kron product between Operator and MathExpr. "
80-
+ "Scalar multiplication of MathExpr and Operator should be bracketed when perfoming Kron product."
81-
)
82-
return OperatorKron(op1=self, op2=other)
77+
if isinstance(other, Operator):
78+
return OperatorKron(op1=self, op2=other)
79+
80+
raise TypeError(
81+
f"Attempted Kron product between Operator and {type(other)}. Double check brackets."
82+
)
8383

8484
def __mul__(self, other):
8585
if isinstance(other, Operator):
@@ -92,7 +92,9 @@ def __rmul__(self, other):
9292
other = MathExpr.cast(other)
9393
return self * other
9494

95-
pass
95+
def __truediv__(self, other):
96+
other = MathExpr.cast(other)
97+
return OperatorScalarMul(op=self, expr=1 / other)
9698

9799

98100
########################################################################################
@@ -154,9 +156,9 @@ def PauliPlus():
154156
Function that constructs the Pauli + operator
155157
"""
156158
return OperatorAdd(
157-
op1=PauliX(),
159+
op1=OperatorScalarMul(op=PauliX(), expr=MathNum(value=0.5)),
158160
op2=OperatorScalarMul(
159-
op=PauliY(), expr=MathMul(expr1=MathImag(), expr2=MathNum(value=1))
161+
op=PauliY(), expr=MathMul(expr1=MathImag(), expr2=MathNum(value=0.5))
160162
),
161163
)
162164

@@ -166,9 +168,9 @@ def PauliMinus():
166168
Function that constructs the Pauli - operator
167169
"""
168170
return OperatorAdd(
169-
op1=PauliX(),
171+
op1=OperatorScalarMul(op=PauliX(), expr=MathNum(value=0.5)),
170172
op2=OperatorScalarMul(
171-
op=PauliY(), expr=MathMul(expr1=MathImag(), expr2=MathNum(value=-1))
173+
op=PauliY(), expr=MathMul(expr1=MathImag(), expr2=MathNum(value=-0.5))
172174
),
173175
)
174176

0 commit comments

Comments
 (0)