Canonicalization
Passes¶
oqd_core.compiler.analog.passes.canonicalize
¶
analog_operator_canonicalization(model)
¶
This pass runs canonicalization chain for Operators with a verifies for canonicalization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
None
Example
- for model = X@(Y + Z), output is 1*(X@Y) + 1 * (X@Z)
- for model = [
AnalogGate
][oqd_core.interface.analog.operations.AnalogGate](hamiltonian = (A * J)@X), output is [AnalogGate
][oqd_core.interface.analog.operations.AnalogGate](hamiltonian = 1 * (X@A)) (where A = Annhiliation(), J = Identity() [Ladder])
Acknowledgement
This code was inspired by Liang.jl.
Source code in oqd-core/src/oqd_core/compiler/analog/passes/canonicalize.py
Rewrite Rules¶
oqd_core.compiler.analog.rewrite.canonicalize
¶
OperatorDistribute
¶
Bases: RewriteRule
RewriteRule which distributes operators of hamiltonians
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
GatherMathExpr
(sometimes)
Example
X@(Y+Z) => X@Y + X@Z
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
GatherMathExpr
¶
Bases: RewriteRule
Gathers the math expressions of Operator
so that we have math_expr * ( Operator
without scalar multiplication)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only modifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
OperatorDistribute
(sometimes)
Example
(1 * X) @ (2 * Y) => (1 * 2) => (1 * 2) * (X @ Y)
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
GatherPauli
¶
Bases: RewriteRule
Gathers ladders and paulis so that we have paulis and then ladders
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only modifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
Example
X@A@Y => X@Y@A
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
PruneIdentity
¶
Bases: RewriteRule
Removes unnecessary ladder Identities from operators
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
GatherMathExpr
,
OperatorDistribute
,
ProperOrder
,
GatherPauli
,
NormalOrder
Example
A*J => A
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
PauliAlgebra
¶
Bases: RewriteRule
RewriteRule for Pauli algebra operations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
Example
X*Y => iZ
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
NormalOrder
¶
Bases: RewriteRule
Arranges Ladder oeprators in normal order form
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
GatherMathExpr
,
OperatorDistribute
,
ProperOrder
,
GatherPauli
Example
AC => CA + J
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
ProperOrder
¶
Bases: RewriteRule
Converts expressions to proper order bracketing. Please see example for clarification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
Example
X @ (Y @ Z) => (X @ Y) @ Z
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
ScaleTerms
¶
Bases: RewriteRule
Scales operators to ensure consistency
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
|
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseModel
|
|
Assumptions
GatherMathExpr
,
OperatorDistribute
,
ProperOrder
,
GatherPauli
,
NormalOrder
,
PruneIdentity
Note
- Requires
GatherMathExpr
right after application ofScaleTerms
for Post walk SortedOrder
andScaleTerms
can be run in either order
Example
X + Y + 2Z => 1X + 1Y + 2Z X@Y => 1*(X@Y)
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
SortedOrder
¶
Bases: RewriteRule
Sorts operators based on TermIndex and collects duplicate terms. Please see example for clarification
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
|
required |
Returns:
Type | Description |
---|---|
model (VisitableBaseModel) |
Assumptions
GatherMathExpr
,
OperatorDistribute
,
ProperOrder
,
GatherPauli
,
NormalOrder
,
PruneIdentity
Note
SortedOrder
andScaleTerms
can be run in either order
Example
(X@Y) + (X@I) => (X@I) + (X@Y) X + I + Z + Y => I + X + Y + Z
Source code in oqd-core/src/oqd_core/compiler/analog/rewrite/canonicalize.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
|
Verification Rules¶
oqd_core.compiler.analog.verify.canonicalize
¶
CanVerPauliAlgebra
¶
Bases: RewriteRule
Checks whether there is any incomplete Pauli Algebra computation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
Example
- X@(Y*Z) => fail
- X@Y => pass
Source code in oqd-core/src/oqd_core/compiler/analog/verify/canonicalize.py
CanVerGatherMathExpr
¶
Bases: RewriteRule
Checks whether all MathExpr have been gathered (i.e. basically checks whether there is any scalar multiplication within a term)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
OperatorDistribute
OperatorDistribute
Example
- X@(1*Z) => fail
- 1*(X@Z) => pass
Source code in oqd-core/src/oqd_core/compiler/analog/verify/canonicalize.py
CanVerOperatorDistribute
¶
Bases: RewriteRule
Checks for incomplete distribution of Operators
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
None
Example
- X@(Y+Z) => fail
- X@Y + X@Z => pass
Source code in oqd-core/src/oqd_core/compiler/analog/verify/canonicalize.py
CanVerProperOrder
¶
Bases: RewriteRule
Checks whether all Operators are ProperOrdered according to how they are bracketed Please see example for clarification
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
None
Example
- X@(Y@Z) => fail
- (X@Y)@Z => pass
Source code in oqd-core/src/oqd_core/compiler/analog/verify/canonicalize.py
CanVerPruneIdentity
¶
Bases: RewriteRule
Checks if there is any ladder Identity present in ladder multiplication
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
OperatorDistribute
OperatorDistribute
Example
- AJC => fail
- A*C => pass
Source code in oqd-core/src/oqd_core/compiler/analog/verify/canonicalize.py
CanVerGatherPauli
¶
Bases: RewriteRule
Checks whether pauli and ladder have been separated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
GatherMathExpr
,
OperatorDistribute
,
ProperOrder
,
PauliAlgebra
Example
- X@A@Y => fail
- X@Y@A => pass
Source code in oqd-core/src/oqd_core/compiler/analog/verify/canonicalize.py
CanVerNormalOrder
¶
Bases: RewriteRule
Checks whether the ladder operations are in normal order
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
OperatorDistribute, GatherMathExpr, ProperOrder, PauliAlgebra, PruneIdentity
GatherMathExpr
,
OperatorDistribute
,
ProperOrder
,
PauliAlgebra
,
PruneIdentity
Example
- A*C => fail
- C*A => pass
Source code in oqd-core/src/oqd_core/compiler/analog/verify/canonicalize.py
CanVerSortedOrder
¶
Bases: RewriteRule
Checks whether operators are in sorted order according to TermIndex. Please see example for further clarification
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
GatherMathExpr
,
OperatorDistribute
,
ProperOrder
,
GatherPauli
,
NormalOrder
,
PruneIdentity
Example
- X + I => fail
- I + X => pass
Source code in oqd-core/src/oqd_core/compiler/analog/verify/canonicalize.py
CanVerScaleTerm
¶
Bases: RewriteRule
Checks whether all terms have a scalar multiplication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
VisitableBaseModel
|
The rule only verifies |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
VisitableBaseMode
|
unchanged |
Assumptions
GatherMathExpr
,
OperatorDistribute
,
ProperOrder
,
GatherPauli
Example
- X + 2*Y => fail
- 1X + 2Y => pass