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

Enable simplification of multi-relation edges & make multi-network construction work with igraph version 2.0.1.1 #250

Merged
merged 6 commits into from
Feb 13, 2024

Conversation

bockthom
Copy link
Collaborator

@bockthom bockthom commented Feb 8, 2024

Prerequisites

  • I adhere to the coding conventions (described here) in my code.
  • I have updated the copyright headers of the files I have modified.
  • I have written appropriate commit messages, i.e., I have recorded the goal, the need, the needed changes, and the location of my code modifications for each commit. This includes also, e.g., referencing to relevant issues.
  • I have put signed-off tags in all commits.
  • I have updated the changelog file NEWS.md appropriately.
  • I have checked whether I need to adjust the showcase file showcase.R with respect to my changes.
  • The pull request is opened against the branch dev.

Description

This PR addresses multiple issues:

  • It fixes Error message logging in metrics.smallwordness is broken #246 (i.e., fixes a broken logerror statement)
  • If adjusts multi-network construction such that it works with the recently released igraph version 2.0.1.1, in which it is not possible any more to add an empty list of vertices. A simple check for an empty list fixes this problem.
  • It updates the README regarding the effectiveness of network conf parameter "artifact.directed", which now is effective as of PR Introduce issue-based artifact-network creation, new tests and fix current tests + minor bug fixes #244.
  • It enables multi-relation edges to be simplified. That is, the simplify methods get an additional parameter and also the network configuration gets an additional parameter to decided whether edges between a pair of vertices should be contracted to a single edge when the edges are of different relations. The default behavior stays as before, that is, edges of different relations are not contracted during simplification. However, notice that the implementation of this feature is not complete, as also the edge attribute handling needs to be adjusted accordingly, and also proper tests are missing. I leave this open to a future PR - I have summarized the steps that are still missing in issue Fix edge-attribute handling when simpliyfing networks #251.

Changelog

Added

Changed/Improved

  • Explicitly add R version 4.3 to the CI test pipeline (9f346d5)

Fixed

@szhorvat
Copy link

szhorvat commented Feb 8, 2024

  • the recently released igraph version 2.0.1.1, in which it is not possible any more to add an empty list of vertices

Can you please elaborate on this, and give an example of what changed? This may not be an intentional change.

@bockthom
Copy link
Collaborator Author

bockthom commented Feb 9, 2024

Can you please elaborate on this, and give an example of what changed? This may not be an intentional change.

Thanks for having a look at our pull request @szhorvat 😄 Sure, I will elaborate on this:

Up until now, we used the "+" operator and igraph::vertices(vertices.to.add, type = type.of.the.vertices.to.add) to add some vertices to a given graph later on. In this situation, vertices.to.add is a vector that could potentially be empty in cases where we don't want to add any vertex, as vertices.to.add is the outcome of some other computations. In particular, if we don't want to add any vertex, it happens that vertices.to.add = character(0), which now leads to the following error in the following example:

graph + igraph::vertices(vertices.to.add, type = type.of.the.vertices.to.add)

Error: Error in `add_vertices(e1, la, attr = e2)`: At rinterface_extra.c:78 : Expecting a scalar integer but received a vector of length 2. Invalid value

As I assumed that character(0) may not be allowed any more in such cases (you might have some good reasons for that), I just fixed this on our side by adding an additional check for length(vertices.to.add) > 0 before executing the statement. If the change in behavior was not intended, I hope my description is helpful for you.

This fixes se-sic#246.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
This can either be done manually when calling 'simplify.network' or
automatically at network creation via a new network configuration
parameter 'simplify.multiple.relations'.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
Since we now have issue artifact networks, the 'artifact.directed'
parameter now is effective for issue artifact networks.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
When adding an empty set of artifact vertices to the multi-network,
adding 'no' vertex fails as of igraph 2.0.1.1. This is easily
fixed by checking whether the set of arftiact vertices to add is
empty, and then just don't call the add function if it is empty.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
This change is a preparation for the release of R version 4.4, which might become
available in the next months and will be covered by R-latest then. To include
R version 4.3 in our CI pipeline, it needs to be explicitly stated.

Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
@bockthom
Copy link
Collaborator Author

bockthom commented Feb 9, 2024

@szhorvat I just encountered another problem in our failing tests which is also related to + igraph::vertices:

author.net =
    igraph::make_empty_graph(n = 0, directed = FALSE) +
    igraph::vertices("A", "B", "C", type = "author", kind = "author") +
    igraph::edges("A", "A", type = "intra", relation = "mail")

In previous versions of igraph, this did not fail. However, with the current igraph version, this fails:
Error in add_vertices(e1, la, attr = e2) : At rinterface_extra.c:78 : Expecting a scalar integer but received a vector of length 2. Invalid value

What I figured out now is the following: Previously, the attributes have automatically been expanded. That is, if I add 3 vertices but the type attribute contains only one element, then the type-attribute vector was automatically expanded and added as an attribute to each added vertex. Now, the code is failing if the attribute vector is not equal to the number of added vertices. (This might also be the problem in the example that I stated some hours ago, where the attribute vector had length one but zero vertices should be added).
I am not sure if this is an intended change in igraph, but the previous version was much more comfortable in this regard - if you want to add numerous vertices that should all have the same value for an attribute, then it was fine to just add an attribute vector of length one and having this one value automatically applied to all vertices... Are you going to fix this again or do we need to fix this on our side by expanding the vector length properly?

@szhorvat
Copy link

szhorvat commented Feb 9, 2024

So it seems that the problem is that if the number of attribute values provided does not match the number of vertices or edges added, then there's an error, even if a single attribute value was given.

This works:

g<-make_empty_graph(1) + vertices('a', 'b', foo=c(2,3))

This does not work, and rightfully so:

g<-make_empty_graph(1) + vertices('a', 'b', foo=c(2,3,4))

But one might expect this to assign na attribute value of 5 to both vertices, yet it does not work:

g<-make_empty_graph(1) + vertices('a', 'b', foo=5)

Am I understanding you correctly?

Pinging @krlmlr to ask if this is indeed expected.

@bockthom
Copy link
Collaborator Author

bockthom commented Feb 9, 2024

So it seems that the problem is that if the number of attribute values provided does not match the number of vertices or edges added, then there's an error, even if a single attribute value was given.

Correct.

This works:

g<-make_empty_graph(1) + vertices('a', 'b', foo=c(2,3))

Sure, this should work.

This does not work, and rightfully so:

g<-make_empty_graph(1) + vertices('a', 'b', foo=c(2,3,4))

Agreed, this should not work.

But one might expect this to assign an attribute value of 5 to both vertices, yet it does not work:

g<-make_empty_graph(1) + vertices('a', 'b', foo=5)

Am I understanding you correctly?

Yes, I totally agree with your understanding.

Pinging @krlmlr to ask if this is indeed expected.

I am not sure if the behavior with regard to multiple vertices and a single-element attribute vector was expected in past versions of igraph - but it was a nice convenience feature to add multiple vertices at once that should all have the same vertex attributes - then passing just one value for each attribute is much more readable and faster to write than extending all the vectors for all attributes to the number of vertices to add. We used this feature of igraph in our test suite for more than 6 years already. But if you think that this should be changed, it is easy to fix on our side. Nevertheless, I'd also be glad if you can restore the previous behavior in igraph 😉

@krlmlr
Copy link

krlmlr commented Feb 9, 2024

With igraph 1.6.0:

options(conflicts.policy = list(warn = FALSE))
library(igraph)

g <-
  make_empty_graph(1) +
  vertices("a", "b", foo = 5)

V(g)$foo
#> [1] NA  5  5

Created on 2024-02-09 with reprex v2.1.0

We clearly had no tests for this, and I agree that this is idiomatic to R.

Copy link
Contributor

@hechtlC hechtlC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good thank you @bockthom
I will merge this now

@hechtlC hechtlC merged commit 0693d7a into se-sic:dev Feb 13, 2024
0 of 6 checks passed
maxloeffler added a commit to maxloeffler/coronet that referenced this pull request Feb 28, 2024
PR se-sic#250 introduces the 'simplify.multiple.relations' configuration option,
which can alter the edge-simplification algorithm for multi-networks.
Correspondingly, the edge-attribute handling does need adjustment to
work with this configuration option.

Disambiguate and sort the 'relation' edge-attribute when simplifying
multi-networks with the 'simplify.multiple.relations' option set.

This works towards se-sic#251.

Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
maxloeffler added a commit to maxloeffler/coronet that referenced this pull request Mar 7, 2024
PR se-sic#250 introduces the 'simplify.multiple.relations' configuration option,
which can alter the edge-simplification algorithm for multi-networks.
Correspondingly, the edge-attribute handling does need adjustment to
work with this configuration option.

Disambiguate and sort the 'relation' edge-attribute when simplifying
multi-networks with the 'simplify.multiple.relations' option set.

This works towards se-sic#251.

Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
@bockthom bockthom mentioned this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants