Skip to content

Commit

Permalink
Merge pull request #1691 from zickgraf/master
Browse files Browse the repository at this point in the history
Defer triggering derivations until `Finalize`
  • Loading branch information
zickgraf authored Sep 25, 2024
2 parents f1c2f91 + 973c992 commit 78bcddb
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 84 deletions.
2 changes: 1 addition & 1 deletion ActionsForCAP/PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SetPackageInfo( rec(

PackageName := "ActionsForCAP",
Subtitle := "Actions and Coactions for CAP",
Version := "2024.08-02",
Version := "2024.09-01",
Date := (function ( ) if IsBound( GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE ) then return GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE; else return Concatenation( ~.Version{[ 1 .. 4 ]}, "-", ~.Version{[ 6, 7 ]}, "-01" ); fi; end)( ),
License := "GPL-2.0-or-later",

Expand Down
1 change: 0 additions & 1 deletion ActionsForCAP/examples/IndirectionTest.g
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ category_with_attributes_record := rec(
triple := EnhancementWithAttributes( category_with_attributes_record );;
indirection_category := triple[1];;
SetIsAbelianCategory( indirection_category, true );;
Reevaluate( indirection_category!.derivations_weight_list );
AddIsEqualForObjects( indirection_category, function( cat, obj1, obj2 ) return UnderlyingCell( obj1 ) = UnderlyingCell( obj2 ); end );;
AddIsEqualForMorphisms( indirection_category, function( cat, mor1, mor2 ) return IsIdenticalObj( mor1, mor2 ); end );;
AddIsCongruentForMorphisms( indirection_category, function( cat, mor1, mor2 ) return UnderlyingCell( mor1 ) = UnderlyingCell( mor2 ); end );;
Expand Down
2 changes: 1 addition & 1 deletion CAP/PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SetPackageInfo( rec(

PackageName := "CAP",
Subtitle := "Categories, Algorithms, Programming",
Version := "2024.09-24",
Version := "2024.09-25",
Date := (function ( ) if IsBound( GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE ) then return GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE; else return Concatenation( ~.Version{[ 1 .. 4 ]}, "-", ~.Version{[ 6, 7 ]}, "-01" ); fi; end)( ),
License := "GPL-2.0-or-later",

Expand Down
7 changes: 0 additions & 7 deletions CAP/gap/Derivations.gi
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,6 @@ function( owl, op_name, new_weight )
owl!.operation_weights.( op_name ) := new_weight;
owl!.operation_derivations.( op_name ) := fail;

# if the weight has not changed, there is no need to re-trigger the chain of derivations
if new_weight <> current_weight then

InstallDerivationsUsingOperation( owl, op_name );

fi;

end );

InstallMethod( PrintDerivationTree,
Expand Down
78 changes: 30 additions & 48 deletions CAP/gap/Finalize.gi
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ InstallMethod( Finalize,
[ "FinalizeCategory", true ],
],
function( CAP_NAMED_ARGUMENTS, category )
local derivation_list, weight_list, current_install, current_final_derivation, op_name, new_weight, current_weight, old_weights, categorical_properties, diff, properties_with_logic, property, i, derivation, operation, property_name, installed_operations_of_homomorphism_structure, original_REORDER_METHODS_SUSPENSION_LEVEL;
local derivation_list, weight_list, current_install, current_final_derivation, op_name, new_weight, current_weight, old_weights, properties_with_logic, property, i, derivation, operation, property_name, installed_operations_of_homomorphism_structure, original_REORDER_METHODS_SUSPENSION_LEVEL;

if IsFinalized( category ) then

Expand All @@ -306,15 +306,6 @@ InstallMethod( Finalize,

fi;

# prepare for the checks below (usually this is done when the first add function is called, but we support the case that no add function is called at all)
if not IsBound( category!.initially_known_categorical_properties ) then

category!.initially_known_categorical_properties := ShallowCopy( ListKnownCategoricalProperties( category ) );

InstallDerivationsUsingOperation( category!.derivations_weight_list, "none" );

fi;

# Warn about categories marked as being computable but not having an implementation of IsCongruentForMorphisms.
# Since IsCongruentForMorphisms currently is derived from IsEqualForMorphisms, the latter also has to be taken into account.
if category!.is_computable and not CanCompute( category, "IsEqualForMorphisms" ) and not CanCompute( category, "IsCongruentForMorphisms") then
Expand All @@ -339,6 +330,18 @@ InstallMethod( Finalize,

weight_list := category!.derivations_weight_list;

InstallDerivationsUsingOperation( weight_list, "none" );

for op_name in SortedList( RecNames( weight_list!.operation_weights ) ) do

if weight_list!.operation_weights.(op_name) <> infinity and weight_list!.operation_derivations.(op_name) = fail then

InstallDerivationsUsingOperation( weight_list, op_name );

fi;

od;

while true do

current_install := fail;
Expand Down Expand Up @@ -429,45 +432,24 @@ InstallMethod( Finalize,

od;

if category!.overhead then

# Check if reevaluation triggers new derivations. Derivations are installed recursively by `InstallDerivationsUsingOperation`, so this should never happen.
# See the WARNING below for possible causes why it still might happen.
old_weights := StructuralCopy( weight_list!.operation_weights );

Info( DerivationInfo, 1, "Starting reevaluation of derivation weight list of the category name \"", Name( category ), "\"\n" );

Reevaluate( weight_list );

Info( DerivationInfo, 1, "Finished reevaluation of derivation weight list of the category name \"", Name( category ), "\"\n" );

categorical_properties := ListKnownCategoricalProperties( category );

if not IsSubset( categorical_properties, category!.initially_known_categorical_properties ) then

Print( "WARNING: The category named \"", Name( category ), "\" has lost the following categorical properties since installation of the first function:\n" );
Display( Difference( category!.initially_known_categorical_properties, categorical_properties ) );

fi;
# TODO: remove once this check has passed the CI of all packages
# Check if reevaluation triggers new derivations. Derivations are installed recursively by `InstallDerivationsUsingOperation`, so this should never happen.
# See the WARNING below for possible causes why it still might happen.
old_weights := StructuralCopy( weight_list!.operation_weights );

Info( DerivationInfo, 1, "Starting reevaluation of derivation weight list of the category name \"", Name( category ), "\"\n" );

Reevaluate( weight_list );

Info( DerivationInfo, 1, "Finished reevaluation of derivation weight list of the category name \"", Name( category ), "\"\n" );

if weight_list!.operation_weights <> old_weights then

if weight_list!.operation_weights <> old_weights then

Print( "WARNING: The installed derivations of the category named \"", Name( category ), "\" have changed by reevaluation, which is not expected at this point.\n" );
Print( "This might be due to one of the following reasons:\n" );
Print( "* The category might have gained a new setting like `supports_empty_limits` since adding the first function. Such settings should always be set before adding functions.\n" );
Print( "* The category filter of some derivation might not fulfill the specification.\n" );

diff := Difference( categorical_properties, category!.initially_known_categorical_properties );

if not IsEmpty( diff ) then

Print( "* The category has gained the following new categorical properties since adding the first function: ", diff, ". Properties should always be set before adding functions for operations which might trigger derivations involving the properties.\n" );

fi;

Print( "For debugging, call `ActivateDerivationInfo( )`, retry, and look at the derivations between \"Starting reevaluation of ...\" and \"Finished reevaluation of ...\".\n" );

fi;
Print( "WARNING: The installed derivations of the category named \"", Name( category ), "\" have changed by reevaluation, which is not expected at this point.\n" );
Print( "This might be due to one of the following reasons:\n" );
Print( "* The category might have gained a new setting like `supports_empty_limits` since adding the first function. Such settings should always be set before adding functions.\n" );
Print( "* The category filter of some derivation might not fulfill the specification.\n" );
Print( "For debugging, call `ActivateDerivationInfo( )`, retry, and look at the derivations between \"Starting reevaluation of ...\" and \"Finished reevaluation of ...\".\n" );

fi;

Expand Down
9 changes: 0 additions & 9 deletions CAP/gap/InstallAdds.gi
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ InstallMethod( AddCapOperation,

fi;

# prepare for the checks in Finalize
if not IsBound( category!.initially_known_categorical_properties ) then

category!.initially_known_categorical_properties := ShallowCopy( ListKnownCategoricalProperties( category ) );

InstallDerivationsUsingOperation( category!.derivations_weight_list, "none" );

fi;

if weight = -1 then
weight := 100;
fi;
Expand Down
2 changes: 1 addition & 1 deletion FreydCategoriesForCAP/PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SetPackageInfo( rec(

PackageName := "FreydCategoriesForCAP",
Subtitle := "Freyd categories - Formal (co)kernels for additive categories",
Version := "2024.09-08",
Version := "2024.09-09",
Date := (function ( ) if IsBound( GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE ) then return GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE; else return Concatenation( ~.Version{[ 1 .. 4 ]}, "-", ~.Version{[ 6, 7 ]}, "-01" ); fi; end)( ),
License := "GPL-2.0-or-later",

Expand Down
18 changes: 9 additions & 9 deletions FreydCategoriesForCAP/gap/AdditiveClosure.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ InstallGlobalFunction( INSTALL_FUNCTIONS_FOR_ADDITIVE_CLOSURE,
SetRangeCategoryOfHomomorphismStructure( category, range_category );
SetIsEquippedWithHomomorphismStructure( category, true );

if ForAll( [ "DirectSum" ], f -> CanCompute( range_category, f ) ) and
if (ForAll( [ "DirectSum" ], f -> CanCompute( range_category, f ) ) or IsIdenticalObj( range_category, category )) and
ForAll( [ "HomomorphismStructureOnObjects" ], f -> CanCompute( underlying_category, f ) ) then

##
Expand All @@ -1090,7 +1090,7 @@ InstallGlobalFunction( INSTALL_FUNCTIONS_FOR_ADDITIVE_CLOSURE,
fi;

# legacy
if ForAll( [ "MorphismBetweenDirectSumsWithGivenDirectSums" ], f -> CanCompute( range_category, f ) ) and
if (ForAll( [ "MorphismBetweenDirectSumsWithGivenDirectSums" ], f -> CanCompute( range_category, f ) ) or IsIdenticalObj( range_category, category )) and
ForAll( [ "HomomorphismStructureOnMorphismsWithGivenObjects" ], f -> CanCompute( underlying_category, f ) ) and
not (IsBound( range_category!.supports_empty_limits ) and range_category!.supports_empty_limits = true) then

Expand Down Expand Up @@ -1130,7 +1130,7 @@ InstallGlobalFunction( INSTALL_FUNCTIONS_FOR_ADDITIVE_CLOSURE,

fi;

if ForAll( [ "MorphismBetweenDirectSumsWithGivenDirectSums" ], f -> CanCompute( range_category, f ) )
if (ForAll( [ "MorphismBetweenDirectSumsWithGivenDirectSums" ], f -> CanCompute( range_category, f ) ) or IsIdenticalObj( range_category, category ))
and ForAll( [ "HomomorphismStructureOnMorphismsWithGivenObjects" ], f -> CanCompute( underlying_category, f ) )
and IsBound( range_category!.supports_empty_limits ) and range_category!.supports_empty_limits = true then

Expand Down Expand Up @@ -1208,9 +1208,9 @@ InstallGlobalFunction( INSTALL_FUNCTIONS_FOR_ADDITIVE_CLOSURE,

fi;

if ForAll( [ "UniversalMorphismIntoZeroObject",
if (ForAll( [ "UniversalMorphismIntoZeroObject",
"UniversalMorphismIntoDirectSum" ],
f -> CanCompute( range_category, f ) ) and
f -> CanCompute( range_category, f ) ) or IsIdenticalObj( range_category, category )) and
ForAll( [ "DistinguishedObjectOfHomomorphismStructure",
"InterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructure" ],
f -> CanCompute( underlying_category, f ) ) and
Expand Down Expand Up @@ -1245,8 +1245,8 @@ InstallGlobalFunction( INSTALL_FUNCTIONS_FOR_ADDITIVE_CLOSURE,

fi;

if ForAll( [ "UniversalMorphismIntoDirectSum" ],
f -> CanCompute( range_category, f ) ) and
if (ForAll( [ "UniversalMorphismIntoDirectSum" ],
f -> CanCompute( range_category, f ) ) or IsIdenticalObj( range_category, category )) and
ForAll( [ "DistinguishedObjectOfHomomorphismStructure",
"InterpretMorphismAsMorphismFromDistinguishedObjectToHomomorphismStructure" ],
f -> CanCompute( underlying_category, f ) ) and
Expand Down Expand Up @@ -1297,9 +1297,9 @@ InstallGlobalFunction( INSTALL_FUNCTIONS_FOR_ADDITIVE_CLOSURE,
if ForAll( [ "HomomorphismStructureOnObjects",
"InterpretMorphismFromDistinguishedObjectToHomomorphismStructureAsMorphism" ],
f -> CanCompute( underlying_category, f ) ) and
ForAll( [ "PreCompose",
(ForAll( [ "PreCompose",
"ProjectionInFactorOfDirectSum" ],
f -> CanCompute( range_category, f ) ) then
f -> CanCompute( range_category, f ) ) or IsIdenticalObj( range_category, category )) then

##
AddInterpretMorphismFromDistinguishedObjectToHomomorphismStructureAsMorphism( category,
Expand Down
3 changes: 0 additions & 3 deletions FreydCategoriesForCAP/gap/CategoryOfRows.gi
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ InstallMethod( CategoryOfRows,

SetIsRigidSymmetricCoclosedMonoidalCategory( cat, true );

# since methods have been added before, we have to reevaluate the derivations
Reevaluate( cat!.derivations_weight_list );

fi;

INSTALL_FUNCTIONS_FOR_CATEGORY_OF_ROWS( cat );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ InstallMethod( CategoryOfRows_as_AdditiveClosure_RingAsCategory,
# These ring properties should actually be propagated to some categorical properties of `ring_as_category`
# which the AdditiveClosure can use generically.
# However, such categorical properties do not (yet) exist, so we have to set the categorical properties
# a posteriori here. Afterwards, we have to reevaluate the derivations because they might have changed
# by setting the properties.
# a posteriori here.
if HasHasInvariantBasisProperty( homalg_ring ) and HasInvariantBasisProperty( homalg_ring ) then

SetIsSkeletalCategory( add, true );
Expand All @@ -50,8 +49,6 @@ InstallMethod( CategoryOfRows_as_AdditiveClosure_RingAsCategory,

fi;

Reevaluate( add!.derivations_weight_list );

Finalize( add );


Expand Down

0 comments on commit 78bcddb

Please sign in to comment.