Skip to content

Commit 3688455

Browse files
committed
Merge branch 'camera-ready' into agent/powerio-v09-migration
2 parents 1aec90a + a5b1f38 commit 3688455

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

‎PowerFlowLimits/Certificate/Core.lean‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,46 @@ namespace PowerFlowLimits.Certificate
1616

1717
/-- One positive weighted branch in a dense zero based bus index space. -/
1818
structure Branch where
19+
/-- Zero based index of one endpoint bus. -/
1920
source : Nat
21+
/-- Zero based index of the other endpoint bus. -/
2022
target : Nat
23+
/-- Series susceptance weight of the branch. Valid branches have positive weight. -/
2124
weight : Rat
22-
deriving Repr, BEq
25+
deriving BEq
2326

2427
/-- The canonical positive weighted DC model supplied by PowerIO. -/
2528
structure Model where
29+
/-- Number of buses. Bus indices run from `0` to `buses - 1`. -/
2630
buses : Nat
31+
/-- All branches of the model. -/
2732
branches : List Branch
28-
deriving Repr, BEq
33+
deriving BEq
2934

3035
/-- A cut is represented by one Boolean membership value per bus. -/
3136
structure CutWitness where
37+
/-- `side[i] = true` when bus `i` belongs to the cut side `S`. -/
3238
side : List Bool
33-
deriving Repr, BEq
39+
deriving BEq
3440

3541
/-- Explicit finite cost model for full angle vector readout. -/
3642
structure Policy where
43+
/-- Readout accuracy target. Divides the quantum cost lower bound. Must be positive. -/
3744
error : Rat
45+
/-- Constant factor of the tomography term in the quantum cost lower bound. Must be positive. -/
3846
tomographyConstant : Rat
47+
/-- Constant factor for the solver queries per tomography repetition. Must be positive. -/
3948
solverGap : Rat
49+
/-- Divisor that discounts the quantum cost lower bound for hybrid schemes. Must be positive. -/
4050
hybridConstant : Rat
51+
/-- Constant factor of the classical cost upper bound. Must be nonnegative. -/
4152
classicalConstant : Rat
53+
/-- Logarithmic factor of the classical cost upper bound. Must be nonnegative. -/
4254
classicalLogFactor : Rat
43-
deriving Repr, BEq
55+
deriving BEq
4456

57+
/-- A branch is valid for an `n` bus model when both endpoints are distinct indices below `n`
58+
and the weight is positive. -/
4559
def Branch.valid (n : Nat) (e : Branch) : Bool :=
4660
e.source < n && e.target < n && e.source != e.target && 0 < e.weight
4761

@@ -66,6 +80,7 @@ private def bfsVisit (adj : Array (List Nat)) :
6680
(visited, [])
6781
bfsVisit adj fuel (fresh ++ queue) visited
6882

83+
/-- Decide whether every bus is reachable from bus `0` along branches. -/
6984
def Model.connected (model : Model) : Bool :=
7085
match model.buses with
7186
| 0 => true
@@ -74,17 +89,22 @@ def Model.connected (model : Model) : Bool :=
7489
let visited := bfsVisit (adjacency model) model.buses [0] start
7590
(List.range model.buses).all (fun bus ↦ visited.getD bus false)
7691

92+
/-- A model is valid when it has at least two buses, every branch is valid, and the branch
93+
graph is connected. -/
7794
def Model.valid (model : Model) : Bool :=
7895
2 ≤ model.buses && model.branches.all (Branch.valid model.buses) && model.connected
7996

97+
/-- Sign checks for the policy constants. -/
8098
def Policy.valid (policy : Policy) : Bool :=
8199
0 < policy.error && 0 < policy.tomographyConstant && 0 < policy.solverGap &&
82100
0 < policy.hybridConstant && 0 ≤ policy.classicalConstant &&
83101
0 ≤ policy.classicalLogFactor
84102

103+
/-- Total branch weight `b(E)`. -/
85104
def totalWeight (model : Model) : Rat :=
86105
model.branches.foldl (fun total branch ↦ total + branch.weight) 0
87106

107+
/-- Total weight of the branches whose endpoints lie on opposite sides of the cut, `b(∂S)`. -/
88108
def cutWeight (model : Model) (witness : CutWitness) : Rat :=
89109
let side := witness.side.toArray
90110
model.branches.foldl
@@ -94,6 +114,7 @@ def cutWeight (model : Model) (witness : CutWitness) : Rat :=
94114
else total)
95115
0
96116

117+
/-- Number of buses on the cut side `S`. -/
97118
def sideCard (witness : CutWitness) : Nat :=
98119
witness.side.foldl (fun count inside ↦ if inside then count + 1 else count) 0
99120

@@ -109,9 +130,11 @@ def cutLowerBound (model : Model) (witness : CutWitness) : Option Rat :=
109130
some (2 * (a : Rat) * (model.buses - a : Nat) * totalWeight model /
110131
((model.buses : Rat) ^ 2 * cut))
111132

133+
/-- Classical cost upper bound `classicalConstant * m * classicalLogFactor`. -/
112134
def classicalCost (model : Model) (policy : Policy) : Rat :=
113135
policy.classicalConstant * model.branches.length * policy.classicalLogFactor
114136

137+
/-- Quantum cost lower bound obtained from the certified condition number lower bound. -/
115138
def quantumCostLower (model : Model) (policy : Policy) (conditionLower : Rat) : Rat :=
116139
policy.tomographyConstant / 2 * policy.solverGap * model.buses * conditionLower /
117140
(policy.hybridConstant * policy.error)

‎PowerFlowLimits/Certificate/Main.lean‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ private def unreadable (error : IO.Error) : IO UInt32 := do
4848
IO.eprintln s!"qpf-check: {error}"
4949
return 2
5050

51+
/-- Entry point of `qpf-check`. Exit code `0` reports an accepted no advantage certificate,
52+
`1` reports an inconclusive check, and `2` reports unreadable or malformed input. -/
5153
def main (args : List String) : IO UInt32 := do
5254
match args with
5355
| [modelPath, policyPath, certificatePath] =>

‎PowerFlowLimits/Certificate/Wire.lean‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private def tokenizeAux : List Char → List Char → List (List Char) → List
4747
tokenizeAux rest [] (if current.isEmpty then output else current.reverse :: output)
4848
else tokenizeAux rest (char :: current) output
4949

50+
/-- Split text into whitespace separated tokens. -/
5051
def tokens (text : String) : List (List Char) := tokenizeAux text.toList [] []
5152

5253
private def parseBranches : Nat → List (List Char) → Option (List Branch × List (List Char))

0 commit comments

Comments
 (0)