oscar-system / jtoric.jl Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://oscar-system.github.io/JToric.jl/dev/
License: MIT License
Home Page: https://oscar-system.github.io/JToric.jl/dev/
License: MIT License
(not camelCase - cf. #38)
Thank you for working on this! I have some minor feedback, after just browsing your source code. Some of them may be nonsense or won't work, as I only read the code, did not try any o this.
export CapAndHomalg
and export GAP
?CapAndHomalg.GAP.Globals
instead of GAP.Globals
?CapAndHomalg.GAP.Globals.ConvertJuliaToGAP(foobar)
seems odd -- I suggest to instead call julia_to_gap(foobar)
or even better, GapObj(foobar)
GAP.Globals.GAPToJulia
, use gap_to_julia
instead -- or even better, if you know the result type, then use that. I.e. if x
is a GAP string, then it's better to write String(x)
than gap_to_julia(x)
, as that allows for reliable type inference, makes the code easier to understand, and adds a layer of protection against mistakesAny
. That prevents optimizations and may also waste storage. Type annotations also help people reading your code to understand it better, and of course they help catch some errorsIsCartier
should be iscartier
, etc.bar
?Array{T,1}
with the equivalent Vector{T}
.Project.toml
accordinglyRegarding the conversion functions, it may also help to use that GAP.jl can convert things recursively. For example, let's look at this function:
function ListOfVariablesOfCoxRing( v::JToricVariety, )
gap_variables = CapAndHomalg.GAP.Globals.ListOfVariablesOfCoxRing( v.GapToricVariety )
len = GAP.Globals.GAPToJulia( GAP.Globals.Length( gap_variables ) )
julia_variables = [ GAP.Globals.GAPToJulia( gap_variables[ i ] ) for i in 1:len ]
return julia_variables
end
I think it could be rewritten to something like this (but I did not verify this; and I only guessed a what type those gap_variable[i]
are supposed to have):
function ListOfVariablesOfCoxRing(v::JToricVariety)
vars = CapAndHomalg.GAP.Globals.ListOfVariablesOfCoxRing(v.GapToricVariety)
return Vector{String}(vars)
end
Or for another example, consider this:
function IsProductOf( v::JToricVariety )
factors = CapAndHomalg.GAP.Globals.IsProductOf( v.GapToricVariety )
len = GAP.Globals.GAPToJulia( GAP.Globals.Length( factors ) )
j_factors = [ JToricVariety( 1, factors[ i ] ) for i in 1:len ]
return j_factors
end
It should be possible to rewrite this as follows:
function IsProductOf(v::JToricVariety)
factors = CapAndHomalg.GAP.Globals.IsProductOf(v.GapToricVariety)
return [ JToricVariety( 1, f ) for f in factors ]
end
As pointed out by @fingolfin (cf. #38).
For various computations, a new GAP object is created via Polymake_V_Rep
and Polymake_H_Rep
. But that really shouldn't be necessary, as Polymake is happy to start with a h-rep or v-rep object which then can be queried for the other rep.
As pointed out by @fingolfin (cf. #38):
You could also use jldoctest, then these examples would also be run as part of the doctest step of the CI (provided that is set up), which has the advantage that the examples are tested, so one knows they actually are working and correct. But of course sometimes this is not desirable, e.g. if outputs are random or differ between Julia versions. Seems to be safe here, though?
Regarding "randomness": The only one that comes to my mind is the one discussed here: #27 I did not see this happen recently, so maybe this is already resolved?
CI tests in various Julia versions (I've seen 1.4, 1.5, 1.6) have been failing. This usually goes away after restarting. Maybe a race condition?
Here's a backtrace of one such failure; unfortunately it is not very useful:
ERROR: Package JToric errored during testing
[1] pkgerror(msg::String)
@ Pkg.Types /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/Types.jl:55
[2] test(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; coverage::Bool, julia_args::Cmd, test_args::Cmd, test_fn::Nothing)
@ Pkg.Operations /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/Operations.jl:1693
[3] test(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; coverage::Bool, test_fn::Nothing, julia_args::Cmd, test_args::Cmd, kwargs::Base.Iterators.Pairs{Symbol, IOContext{Base.PipeEndpoint}, Tuple{Symbol}, NamedTuple{(:io,), Tuple{IOContext{Base.PipeEndpoint}}}})
@ Pkg.API /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/API.jl:343
[4] test(pkgs::Vector{Pkg.Types.PackageSpec}; io::IOContext{Base.PipeEndpoint}, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:coverage,), Tuple{Bool}}})
@ Pkg.API /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/API.jl:80
[5] test(; name::Nothing, uuid::Nothing, version::Nothing, url::Nothing, rev::Nothing, path::Nothing, mode::Pkg.Types.PackageMode, subdir::Nothing, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:coverage,), Tuple{Bool}}})
@ Pkg.API /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Pkg/src/API.jl:96
[6] top-level scope
@ none:1
@fingolfin @lkastner: For efficient collaboration, I think you should have sufficient permissions (write, merge etc.). Does it make sense to migrate this repository to Oscar?
I have done similar transitions in the past. It should be possible to hand over this private repository to an organization (e.g. Oscar). In particular, this transition should (?) also preserve issues, PRs etc.
We should have methods to compute topological intersection numbers. Specifically, I am thinking of smooth, complete, normal toric varieties of dimension N. For toric divisors D1, D2, ..., DN, the topological intersection number D1 * D2 * ... * DN is then a (finite) integer, which we should be able to compute.
Extensions would be towards orbifolds, with typically rational intersection numbers (if well-defined). Another extension is to support operations with the full intersection rings. This would start by having support for the Cox ring and its quotient by the sum of the Stanley-Reisner ideal and the ideal of linear relations.
Right now, JToric uses a patched version of NConvex in order to allow the JConvex GAP package to override the NConvex code calling Normaliz/Cddlib, by code which calls Polymake (through Julia / Polymake.jl) instead.
We don't want this on the long run. Rather, we want to work with @kamalsaleh and @mohamed-barakat to get changes into NConvex that allow us to use that again. There are several ways to do this:
Option 3 sounds the cleanest on paper, but it's also most work, I think, and it's not clear who would make the decision which "provider" of functionality to actually load, and when. This is solved better with 1 and 2. The drawback of 1 is that we are currently still changing JConvex a lot; and ideally I think we should have it inside the JToric.jl repository, so that we can change it in lock step with the rest of JToric. So from that point of view, option 2 would be best, except if not done carefully, it'd degrade the user experience for people using "regular" GAP (for those ideally nothing would change).
So here's a slightly crazy idea: as a slight variant of approach (2), the PackageInfo.g
of NConvex could be changed to look something like this:
# if running GAP under Julia and JConvex is around, then use that
if IsPackageMarkedForLoading("JuliaInterface", "") and TestPackageAvailability("JConvex") then
nconvex_needed := [ [ "JConvex" ] ];
else
nconvex_needed := [ [ "CddInterface", ">= 2020.06.24" ],
[ "NormalizInterface", ">= 1.1.0" ] ];
fi;
SetPackageInfo( rec(
PackageName := "NConvex",
...
Dependencies := rec(
GAP := ">= 4.9",
NeededOtherPackages := Concatenation([ [ "AutoDoc", ">= 2018.02.14" ],
[ "Modules", ">= 0.5" ],
[ "CddInterface", ">= 2020.06.24" ],
[ "NormalizInterface", ">= 1.1.0" ]
],
...
));
Unbind(nconvex_needed);
```
When I refactored JConvex, I replaced code like this:
s := JuliaToGAP( IsString, Julia.string( cone!.pmobj.RAYS ) );
res_string := SplitString( s, '\n' );
res_string := List( [ 2 .. Length( res_string ) ], i -> Concatenation( "[", ReplacedString( res_string[ i ], " ", "," ), "]" ) );
rays := EvalString( Concatenation( "[", JoinStringsWithSeparator( res_string, "," ), "]" ) );
by stuff like this:
rays := JuliaToGAP( IsList, JuliaMatrixInt( cone!.pmobj.RAYS ) );
where JuliaMatrixInt
really is the Julia type Matrix{Int}
.
I think that was a mistake. We probably should be using Matrix{Rational{BigInt}}
. Because JConvex then often proceeds with code like this:
# sometimes, Polymake returns rational rays - we turn them into integral vectors
scaled_rays := [];
for i in [ 1 .. Length( rays ) ] do
scale := Lcm( List( rays[ i ], r -> DenominatorRat( r ) ) );
Append( scaled_rays, [ scale * rays[ i ] ] );
od;
From @lkastner I learned that one can let Polymake do this scaling, by calling Polymake.common.primitive
. So perhaps even better would be to replace all that scaling code by something like that (note the use of a to-be-defined JuliaMatrixBigInt
):
rays := _Polymake_jl.common.primitive( cone!.pmobj.RAYS ); # ensure integer coeffs
rays := JuliaToGAP( IsList, JuliaMatrixBigInt( rays ) );
and then `scaled_rays is superfluous.
Julia convention suggests this, and the Julia package manager requires this, I think (if this package ever is to be registered).
Say: AffineToricVariety,
ProjectiveToricVariety,
NormalToricVariety,
...
using GAP
and using CapAndHomalg
strictly necessary? In particular, they currently appear (at least) once in every file in the src-folder.CapAndHomalg.LoadPackage(
"ToricVarieties" ) (and the same for JConvex
and JuliaInterface
) might be redundant (replace by GAP.LoadPackage()
or alike?)Julia 1.3
and latest
.If we want the physics community to be interested, then we must allow to construct toric varieties from triangulations.
Typical example: Given a polytope, work out all of its FRSTs (fine, regular, star triangulations) and return a list/array of the toric varieties that are build from the different triangulations.
So clearly this is a local problem as the CI tests pass here. But I am wondering what might be wrong here!
I already tried running Pkg.build( "JToric" )
again. No such luck. Perhaps @HereAround has a hint
Precompiling project...
1 dependency successfully precompiled in 28 seconds (86 already precompiled)
Testing Running tests...
Welcome to JToric 0.1.0
Enjoy this software to perform computations on toric geometry!
JToric.jl: Error During Test at /Users/mhorn/Projekte/OSCAR/JToric/test/runtests.jl:16
Test threw exception
Expression: JToric.is_isomorphic_to_projective_space(H5) == false
Error thrown by GAP: Syntax error: identifier expected in stream:1
_EVALSTRINGTMP:={0};
^
Syntax error: -> expected in stream:1
�
Error, Could not evaluate string.
at /Users/mhorn/.julia/artifacts/8f22bf2645df36936a8a74cea9de55d6070017ed/share/gap/lib/string.gi:658 called from
EvalString( res_string[i] ) at /Users/mhorn/.julia/packages/CapAndHomalg/PE2rB/pkg/ToricVarieties_project/JConvex/gap/ExternalPolymakeCone.gi:442 called from
func( C[i] ) at /Users/mhorn/.julia/artifacts/8f22bf2645df36936a8a74cea9de55d6070017ed/share/gap/lib/coll.gi:665 called from
List( [ 2 .. Length( res_string ) ], function ( i )
return EvalString( res_string[i] );
end ) at /Users/mhorn/.julia/packages/CapAndHomalg/PE2rB/pkg/ToricVarieties_project/JConvex/gap/ExternalPolymakeCone.gi:442 called from
Polymake_RaysInFacets( ExternalPolymakeCone( cone ) ) at /Users/mhorn/.julia/packages/CapAndHomalg/PE2rB/pkg/ToricVarieties_project/JConvex/gap/Cone.gi:112 called from
RaysInFacets( cone ) at /Users/mhorn/.julia/gaproot/v4.12/pkg/NConvex/gap/Cone.gi:613 called from
... at *defin*:0
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] ThrowObserver(depth::Int32)
@ GAP ~/.julia/packages/GAP/9XZl9/src/GAP.jl:63
[3] _call_gap_func(func::GAP.GapObj, a1::GAP.GapObj)
@ GAP ~/.julia/packages/GAP/9XZl9/src/ccalls.jl:255
[4] call_gap_func_nokw
@ ~/.julia/packages/GAP/9XZl9/src/ccalls.jl:222 [inlined]
[5] (::GAP.GapObj)(a1::GAP.GapObj)
@ GAP ~/.julia/packages/GAP/9XZl9/src/ccalls.jl:232
[6] is_isomorphic_to_projective_space(v::NormalToricVariety)
@ JToric ~/Projekte/OSCAR/JToric/src/ToricVarieties.jl:337
[7] macro expansion
@ ~/Projekte/OSCAR/JToric/test/runtests.jl:16 [inlined]
[8] macro expansion
@ /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined]
[9] top-level scope
The following is a list of tasks that I believe would be interesting to look into for toric varieties.
Of course, I do not claim that this list is complete, neither that the points need to be addressed in this order. Some of the points might also be debatable/need to be sharpened. Still, I hope that this gives a first impression of a possible roadmap.
I would be happy to hear what people think about this.
e
.)Methods for AffineNormalToricVariety shoud also be callable by a NormalToricVariety v in case isaffine( v ) == true. However, the following leads to an error:
C = Oscar.positive_hull([1 1; -1 1])
ntv = NormalToricVariety(C)
isaffine( ntv )
toric_ideal_binomial_generators( ntv )
@lkastner Suggestions?
Eventually, we should directly ask polymake about fans/cones, rather than using its wrapper for ToricVarieties (avoiding code duplication/simplification). This can probably be considered as an improvement of the code style.
[For now postponed in favour of adding functionality.]
(Cf. #34)
As suggested by @fingolfin in #38, properly call/import Polymake
in JToric
:
__init__
of JToric
by JToric.GAP.Globals.pm = Polymake
(pm to be replaced by __Polymake
or __PolymakeFromJulia
or so or POLYMAKE_JULIA_MODULE
or whatever, just to avoid clashes with user objects.Polymake
via pm.prefered_function
.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.