Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve pre_dcp, and some docs and clean-up #18

Merged
merged 66 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
eef13f2
doc: change reference style
ramonfmir Feb 6, 2024
7489fe4
chore: merge main
ramonfmir Feb 6, 2024
dfb3de3
doc: `Tactic/Arith`
ramonfmir Feb 6, 2024
1634bdf
fix: paths in docstrings
ramonfmir Feb 6, 2024
a5e1d6c
doc: some more comments on commands
ramonfmir Feb 6, 2024
09c7c61
feat: many custom error messages
ramonfmir Feb 6, 2024
79f6f9c
doc: half of basic tactics
ramonfmir Feb 6, 2024
80c4c00
feat: add some reverse egg rules
ramonfmir Feb 10, 2024
f625828
feat: min and max rewrite rules
ramonfmir Feb 10, 2024
00db033
refactor: `RewriteMap` -> `RuleToTactic`
ramonfmir Feb 11, 2024
29468c0
refactor: `addRealToFloat` -> `add_real_to_float`
ramonfmir Feb 11, 2024
e5449df
wip: working with binders
ramonfmir Feb 12, 2024
17d95af
chore: remove unsafe atom data definition
ramonfmir Feb 12, 2024
8649b6e
chore: update `Cargo.lock`
ramonfmir Feb 12, 2024
242cadf
wip: add `stop_on_success` option
ramonfmir Feb 14, 2024
1472ced
chore: keep track of all times
ramonfmir Feb 14, 2024
c4362c7
feat: refine DGP tests
ramonfmir Feb 14, 2024
b5bfff8
refactor: no "convexify" in `egg` test util
ramonfmir Feb 14, 2024
47faebd
fix: conditional compilation in extractor
ramonfmir Feb 14, 2024
a57ea61
fix: `egg` DGP tests formatting
ramonfmir Feb 14, 2024
0e4136e
feat: option to add node limit to environment
ramonfmir Feb 14, 2024
65c7d49
doc: note on some issues with `norm2`
ramonfmir Feb 15, 2024
c89ad16
wip: aligning tests
ramonfmir Feb 15, 2024
9d656cd
chore: better `egg` error messages
ramonfmir Feb 15, 2024
2f5c02b
chore: no "convexify"
ramonfmir Feb 15, 2024
4643ca7
feat: `make_float`
ramonfmir Feb 15, 2024
ceef9ee
test: more DQCP tests
ramonfmir Feb 15, 2024
2474ca9
chore: clearer `egg` debug messages
ramonfmir Feb 15, 2024
8c8c9d6
chore: print result for extraction in QCP tests
ramonfmir Feb 15, 2024
37e4bb7
wip: put holes in expected expressions
ramonfmir Feb 17, 2024
fb29563
wip: `pre_dcp` only rewrites sub-expressions
ramonfmir Feb 17, 2024
4e1c1b4
fix: `log_eq_log` direction
ramonfmir Feb 17, 2024
3245786
feat: rule to tactic without rewriting or simplifying
ramonfmir Feb 17, 2024
6266bdd
fix: handle propositional rewrites separately
ramonfmir Feb 17, 2024
d3e6f69
test: clean up DQCP test
ramonfmir Feb 17, 2024
05c23a6
fix: compute term size
ramonfmir Feb 17, 2024
d9b7b18
chore: align Stanford tests
ramonfmir Feb 17, 2024
cd925a7
fix: account for domain constraints in term size
ramonfmir Feb 17, 2024
40c3d43
test: add Stanford
ramonfmir Feb 17, 2024
f052f30
test: modules for tests
ramonfmir Feb 17, 2024
69ec34f
test: environment node limit in expression tests
ramonfmir Feb 17, 2024
8a3706a
fix: control cost partial order
ramonfmir Feb 17, 2024
38b76ae
fix: if `stop_on_success`, we do not know about `Cost`
ramonfmir Feb 17, 2024
c974029
test: all `egg` tests in modules
ramonfmir Feb 18, 2024
577bd69
feat: specify expression in `rw_obj` and `rw_constr`
ramonfmir Feb 18, 2024
cd1cc6d
feat: `rw_obj` in fitting sphere
ramonfmir Feb 18, 2024
1a62df3
feat: rewriting into in hypersonic shape design
ramonfmir Feb 18, 2024
13249d3
fix: `whnf` in tactic builder
ramonfmir Feb 18, 2024
c08d4e3
fix: labels in `rw_constr` and `setGoals`
ramonfmir Feb 18, 2024
104b141
feat: simplify truss design
ramonfmir Feb 18, 2024
2182ad6
feat: simplify vehicle speed scheduling
ramonfmir Feb 18, 2024
72caf58
feat: more robust change of variables
ramonfmir Feb 18, 2024
ef45665
feat: tactic builders can return values
ramonfmir Feb 18, 2024
9e2ba2d
fix: throw away names in `pre_dcp`
ramonfmir Feb 18, 2024
cad3f90
wip: new motivating usability example
ramonfmir Feb 18, 2024
0820639
feat: rewrite into in usability example
ramonfmir Feb 18, 2024
9ee5a52
feat: add evaluation scripts
ramonfmir Feb 19, 2024
13e9be8
wip: some type theory checks
ramonfmir Feb 21, 2024
d12d468
wip: fix equivalence proofs
ramonfmir Feb 21, 2024
aee97be
doc: sections in equivalence lib
ramonfmir Feb 22, 2024
00fc029
refactor: move `PosSemiDef.IsSymm` to library
ramonfmir Feb 22, 2024
eb9ff07
chore: remove `WIP` from demos
ramonfmir Feb 22, 2024
723c2b9
fix: use `arith` in `change_of_variables`
ramonfmir Feb 22, 2024
92c4035
fix: add current namespace in declarations from `solve`
ramonfmir Feb 22, 2024
852ddf6
fix: new `remove_constr` syntax
ramonfmir Feb 22, 2024
54c5eff
fix: do not solve `dcp6` (from `gp6`), MOSEK error only in CI
ramonfmir Feb 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*.code-workspace

/playground
/evaluation
/scripts/evaluation/data
/plots

/CvxLean/Tactic/Solver/Mosek/Path.lean
2 changes: 2 additions & 0 deletions CvxLean/Command/Equivalence.lean
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ type `Equivalence p q`. -/
def elabEquivalenceProof (lhs : Expr) (rhsName : Name) (stx : Syntax) : TermElabM (Expr × Expr) :=
elabTransformationProof TransformationGoal.Equivalence lhs rhsName stx

/-- Open an equivalence environment. -/
syntax (name := equivalence)
"equivalence" ident "/" ident declSig ":=" Lean.Parser.Term.byTactic : command

/-- Open an equivalence environment and try to generate a computable backward map. -/
syntax (name := equivalenceAndBwdMap)
"equivalence'" ident "/" ident declSig ":=" Lean.Parser.Term.byTactic : command

Expand Down
4 changes: 3 additions & 1 deletion CvxLean/Command/Reduction.lean
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ environment:
Writing `reduction'` instead of `reduction` will also generate a backward solution map at the
level of floats.

It is essentially the same as `Command/Equivalence.lean`, except that the goal is to prove a
It is essentially the same as `CvxLean/Command/Equivalence.lean`, except that the goal is to prove a
reduction instead of an equivalence. We note that proving that two problems are equivalent is
usually preferred.
-/
Expand All @@ -45,9 +45,11 @@ type `Reduction p q`. -/
def elabReductionProof (lhs : Expr) (rhsName : Name) (stx : Syntax) : TermElabM (Expr × Expr) :=
elabTransformationProof TransformationGoal.Reduction lhs rhsName stx

/-- Open a reduction environment. -/
syntax (name := reduction)
"reduction" ident "/" ident declSig ":=" Lean.Parser.Term.byTactic : command

/-- Open a reduction environment and try to generate a computable backward map. -/
syntax (name := reductionAndBwdMap)
"reduction'" ident "/" ident declSig ":=" Lean.Parser.Term.byTactic : command

Expand Down
11 changes: 6 additions & 5 deletions CvxLean/Command/Relaxation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ environment:
* `q := r`,
* `rel : p ≽' q`.

This command is very similar to `equivalence` (`Command/Equivalence.lean`) and `reduction`
(`Command/Reduction.lean`) in how it is designed. Of course, the key difference is that the goal
is to prove a relaxation. Note that in this case, there is no option to create a backward map as
relaxations do not guarantee that the solution can be mapped back.
This command is very similar to `equivalence` (`CvxLean/Command/Equivalence.lean`) and `reduction`
(`CvxLean/Command/Reduction.lean`) in how it is designed. Of course, the key difference is that the
goal is to prove a relaxation. Note that in this case, there is no option to create a backward map
as relaxations do not guarantee that the solution can be mapped back.
-/

namespace CvxLean
Expand All @@ -39,10 +39,11 @@ type `Relaxation p q`. -/
def elabRelaxationProof (lhs : Expr) (rhsName : Name) (stx : Syntax) : TermElabM (Expr × Expr) :=
elabTransformationProof TransformationGoal.Relaxation lhs rhsName stx

/-- Open a relaxation environment. -/
syntax (name := relaxation)
"relaxation" ident "/" ident declSig ":=" Lean.Parser.Term.byTactic : command

/-- Relaxation command. -/
/-- Definition of the `relaxation` command. -/
@[command_elab «relaxation»]
def evalRelaxation : CommandElab := fun stx => match stx with
| `(relaxation $relIdStx / $probIdStx $declSig := $proofStx) => do
Expand Down
3 changes: 2 additions & 1 deletion CvxLean/Command/Solve.lean
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def getProblemName (stx : Syntax) : MetaM Name := do
if ¬ idStx.getId.isStr then
throwError "Invalid name for minimization problem: {idStx}."

return idStx.getId
let currNamespace ← getCurrNamespace
return currNamespace ++ idStx.getId

/-- Call DCP and get the problem in conic form as well as `ψ`, the backward map from the
equivalence. -/
Expand Down
6 changes: 3 additions & 3 deletions CvxLean/Command/Solve/Float/Coeffs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import CvxLean.Command.Solve.Float.RealToFloatLibrary
# Extract coefficients from problem to generate problem data

This file defines `determineCoeffsFromExpr`, which takes a `MinimizationExpr` and returns
`ProblemData`. This procedure is used by `Commands/Solve.lean` to be able to call an external
solver.
`ProblemData`. This procedure is used by `CvxLean/Commands/Solve.lean` to be able to call an
external solver.

## TODO
### TODO

* This is probably a big source of inefficency for the `solve` command. We should come up with a
better way to extract the numerical values from the Lean expressions.
Expand Down
4 changes: 2 additions & 2 deletions CvxLean/Command/Solve/Float/FloatToReal.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Mathlib.Data.Real.Basic
import CvxLean.Lib.Math.Data.Real

/-!
Conversion used in `Solve/Conic.lean` to read the solver's output into an expression to which we can
apply the backward map.
Conversion used in `CvxLean/Command/Solve/Conic.lean` to read the solver's output into an expression
to which we can apply the backward map.
-/

namespace CvxLean
Expand Down
4 changes: 2 additions & 2 deletions CvxLean/Command/Solve/Float/ProblemData.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We provide an interface to build this data by adding any of the possible types o
data can then be transformed in a straightforward manner into Conic Benchmark Format, for example.

The procedure that creates `ProblemData` from an optimization problem can be found in
`Command/Solve/Coeffs.lean`.
`CvxLean/Command/Solve/Coeffs.lean`.
-/

namespace CvxLean
Expand Down Expand Up @@ -115,7 +115,7 @@ def addZeroConstraint (data : ProblemData) (a : Array Float) (b : Float) : Probl
/-- Add exponential cone constraint `∑ i, aᵢxᵢ + b ∈ 𝒦ₑ` to problem data. Note that the
second-order cone is `3`-dimensional, so to capture `(x, y, z) ∈ 𝒦ₑ` we do `x ∈ 𝒦ₑ`, `y ∈ 𝒦ₑ`, and
`z ∈ 𝒦ₑ` consecutively. We keep track of how to group consecutive constraints in
`Command/Solve/Float/Coeffs.lean`. -/
`CvxLean/Command/Solve/Float/Coeffs.lean`. -/
def addExpConstraint (data : ProblemData) (a : Array Float) (b : Float) : ProblemData :=
data.addScalarAffineConstraintOnlyVector a b ScalarConeType.Exp

Expand Down
18 changes: 9 additions & 9 deletions CvxLean/Command/Solve/Float/RealToFloatCmd.lean
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import CvxLean.Command.Solve.Float.RealToFloatExt
# Conversion of Real to Float (command)

We define the `realToFloat` function to go from real `Expr`s to float `Expr`s as well as the
`addRealToFloat` command to add new translations and the `#realToFloat` command to test the
`add_real_to_float` command to add new translations and the `#real_to_float` command to test the
translation.
-/

Expand All @@ -23,7 +23,7 @@ namespace CvxLean
open Lean Expr Elab Meta Command Term

syntax (name := addRealToFloatCommand)
"addRealToFloat" Lean.Parser.Term.funBinder* ":" term ":=" term : command
"add_real_to_float" Lean.Parser.Term.funBinder* ":" term ":=" term : command

/-- Traverse expression recursively and if a match is found in the real-to-float library return the
float version. The "correctness" of this function depends on the translations defined in the
Expand Down Expand Up @@ -72,31 +72,31 @@ partial def realToFloat (e : Expr) : MetaM Expr := do
return e
| _ => return e

/-- The `addRealToFloat` command, which simply adds the user-defined expressions to the environment
extension. -/
/-- The `add_real_to_float` command, which simply adds the user-defined expressions to the
environment extension. -/
@[command_elab addRealToFloatCommand]
def elabAddRealToFloatCommand : CommandElab
| `(addRealToFloat : $real := $float) =>
| `(add_real_to_float : $real := $float) =>
liftTermElabM do
let real ← elabTermAndSynthesize real.raw none
let float ← elabTermAndSynthesize float.raw none
addRealToFloatData { real := real, float := float }
| _ => throwUnsupportedSyntax

macro_rules
| `(addRealToFloat $idents:funBinder* : $real := $float) => do
| `(add_real_to_float $idents:funBinder* : $real := $float) => do
if idents.size != 0 then
`(addRealToFloat : fun $idents:funBinder* => $real := fun $idents:funBinder* => $float)
`(add_real_to_float : fun $idents:funBinder* => $real := fun $idents:funBinder* => $float)
else
Macro.throwUnsupported

syntax (name:=realToFloatCommand)
"#realToFloat" term : command
"#real_to_float" term : command

/-- Transform the given expression to its float version and log the result. -/
@[command_elab realToFloatCommand]
unsafe def elabRealToFloatCommand : CommandElab
| `(#realToFloat $stx) =>
| `(#real_to_float $stx) =>
liftTermElabM do
let e ← elabTermAndSynthesize stx.raw none
let res ← realToFloat e
Expand Down
Loading
Loading