wangjie212 / TSSOS

A sparse polynomial optimization tool based on the moment-SOS hierarchy.
MIT License
39 stars 14 forks source link

How to run the examples #7

Closed richardrl closed 1 year ago

richardrl commented 1 year ago

Hi, I'm new to Julia, and wasn't able to run the examples even after searching a bit.

This command does not work:

julia --project=. ./example/polynomials.jl
ERROR: LoadError: UndefVarError: @polyvar not defined
in expression starting at /home/<redacted>/TSSOS/example/polynomials.jl:4
in expression starting at /home/<redacted>/TSSOS/example/polynomials.jl:4

How do I get it to work?

I also tried this:

julia> using TSSOS

julia> using DynamicPolynomials

julia> include("example/polynomials.jl")
┌ Warning: Assignment to `f` in soft scope is ambiguous because a global variable by the same name exists: `f` will be treated as a new local. Disambiguate by using `local f` to suppress this warning or `global f` to assign to the existing global variable.
└ @ ~/improbable/TSSOS/example/polynomials.jl:16
ERROR: LoadError: UndefVarError: f not defined
Stacktrace:
 [1] top-level scope
   @ ~/improbable/TSSOS/example/polynomials.jl:16
 [2] include(fname::String)
   @ Base.MainInclude ./client.jl:476
 [3] top-level scope
   @ REPL[3]:1
in expression starting at /home/<redacted>/TSSOS/example/polynomials.jl:15
richardrl commented 1 year ago

Figured it out.

To use this file, comment everything except the function you want, and make a new optimization.jl file:

using TSSOS
using DynamicPolynomials
include("polynomials.jl")
opt,sol,data = tssos_first(f, x, TS="MD")

and add using DynamicPolynomials to the polynomials.jl file