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

wrong count return by nreal #406

Closed
jaydu1 opened this issue Sep 20, 2020 · 2 comments · Fixed by #407
Closed

wrong count return by nreal #406

jaydu1 opened this issue Sep 20, 2020 · 2 comments · Fixed by #407

Comments

@jaydu1
Copy link

jaydu1 commented Sep 20, 2020

The nreal function should return 2 in this case. Is something wrong with this function?

result

The following code should be able to reproduce the problem.

n = 2;
A = matrixdepot("fiedler", n);
B = matrixdepot("moler", n);
    
@var u[1:2n] σ[1:2] C₀[1:2n,1:2n] C₁[1:2n,1:2n] C₂[1:2n,1:2n]
f = System([(C₀-σ[1]*C₁-σ[2]*C₂)*u; 
            (σ'*σ-1)/2;
            (u'*u-1)/2], 
            variable_groups=[σ, u], 
            parameters=[C₀[:]; C₁[:]; C₂[:]])
result = solve(f;
        show_progress=false,
        stop_early_cb = r -> true,
        start_system = :total_degree,
        target_parameters=rand(3*(2n)^2))

function partial(f,a...)
    ( (b...) -> f(a...,b...) )
end

function is_valid(sigma, r)
    if is_real(r)
        sol = solution(r)
        if abs(-sigma-maximum(real(eigvals(real(sol[1])*A+real(sol[2])*B))))<1e-16
            return true;
        end
    end
    return false
end

_seed = 5;
sigma = 0.71875;
C0 = -sigma*Matrix{Float64}(I, n, n);
C1 = A;
C2 = B;
C0 = [C0 zeros(size(C0));zeros(size(C0)) C0];
C1 = [real(C1) -imag(C1);imag(C1) real(C1)];
C2 = [real(C2) -imag(C2);imag(C2) real(C2)];

result = solve(f;
            show_progress=false,
            seed=UInt32(_seed),
            stop_early_cb = partial(is_valid, sigma),
            start_system = :total_degree,
            target_parameters=[C0[:];C1[:];C2[:]])

println(nreal(result)==size(results(result, only_real = true))[1])
# false
@saschatimme
Copy link
Member

Hey @jaydu1 many thanks for the bug report. I couldn't reproduce the bug from your example, but I think I found nonetheless the problem.
I tagged a new release (2.0.7) which should be available in an hour or so. Let me know if the problem still occurs.

@jaydu1
Copy link
Author

jaydu1 commented Sep 20, 2020

It works now. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants