@@ -16,32 +16,46 @@ namespace PowerFlowLimits.Certificate
1616
1717/-- One positive weighted branch in a dense zero based bus index space. -/
1818structure 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. -/
2528structure 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. -/
3136structure 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. -/
3642structure 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. -/
4559def 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. -/
6984def 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. -/
7794def 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. -/
8098def 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)`. -/
85104def 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)`. -/
88108def 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`. -/
97118def 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`. -/
112134def 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. -/
115138def quantumCostLower (model : Model) (policy : Policy) (conditionLower : Rat) : Rat :=
116139 policy.tomographyConstant / 2 * policy.solverGap * model.buses * conditionLower /
117140 (policy.hybridConstant * policy.error)
0 commit comments