Skip to content

Simplify combined_networks: list-based class with lazy block-diagonal construction#44

Closed
Copilot wants to merge 5 commits intomasterfrom
copilot/simplify-combined-networks-structure
Closed

Simplify combined_networks: list-based class with lazy block-diagonal construction#44
Copilot wants to merge 5 commits intomasterfrom
copilot/simplify-combined-networks-structure

Conversation

Copy link

Copilot AI commented Mar 15, 2026

combined_networks previously built an eager block-diagonal network object and stored constituent networks in a .subnetcache attribute, wasting memory and complicating the data structure. The new design stores constituent networks directly and builds the block-diagonal on demand — analogous to how networkLite has a different internal representation but the same S3 API.

New internal structure

structure(
  list(
    nw  = list(nw1, nw2, ...),   # constituent networks (complete, with edges)
    gal = list(                   # network-level metadata (like networkLite$gal)
      n = total_n, directed = ..., bipartite = ...,
      ".blockID.vattr" = ..., ".subnetattr" = ..., ...
    )
  ),
  class = c("combined_networks", "network")
)

Changes

  • R/combined_networks_methods.R (new): Full S3 method suite — get/set/list/delete.network.attribute, get/set/list/delete.vertex.attribute, network.size, is.directed, network.edgecount, as.matrix, and a .clear_edges() helper compatible with both network and networkLite

  • R/combine.networks.R:

    • combine_networks() populates $nw + $gal; no longer allocates a block-diagonal network at construction time
    • as.networkLite.combined_networks() builds the block-diagonal on demand (vertex attributes, edge list remapping, nested block-ID handling for both unipartite and bipartite cases)
    • uncombine_network() for list-based objects simply returns $nw; for post-simulation networkLite-based objects, new .uncombine_network_from_blockdiag() uses block offsets instead of get.inducedSubgraph()
    • Block-ID and block-name vertex attributes are now virtual — computed from the list structure, not stored per-vertex; nested combined networks produce nested block-ID vectors correctly
  • R/multinet.R: as_tibble.combined_networks delegates edge/vertex units to as_tibble(as.networkLite(x)) instead of NextMethod (which would fail on the list structure)

  • R/print.combined_networks.R: print/summary/print.summary simplified; NextMethod() removed (incompatible with the list-based layout)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/EpiModel/networkLite/contents/R
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Simplify combined_networks structure?</issue_title>
<issue_description>Currently, the system is designed to, in principle, be able to un-combine networks in any order. It may make sense to instead mandate that the networks be uncombined in the same order as they are combined. This will simplify the data structure and save memory. It may also make sense to store subnetwork information not on vertices but on subnetworks (and the .subnetattr of the combined network).

uncombine_networks() can also be simplified, since we would then only need to take the .subnetcache networks and copy the edges.

This is related to #42, since it needs to assume that the uncombining is done in reverse order of the combining.</issue_description>

<agent_instructions>Try to implement the approach of creating a list-based object that implements all the methods of network::network objects.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@krivit What if, instead of actually constructing a `network` object, the `combined_networks` class were a `list` of constituent networks (which themselves may be `combined_networks`) with some metadata that helped map vertex indices of the combined network onto the index of the subnetwork and its vertex index. Then, a suite of accessors and motifiers could be implemented that would propagate the methods for `network` objects in the `network` package onto the subnetworks.

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI and others added 4 commits March 15, 2026 06:05
Co-authored-by: krivit <15682462+krivit@users.noreply.github.com>
…etwork template handling, and NextMethod usage

Co-authored-by: krivit <15682462+krivit@users.noreply.github.com>
…, improve .clear_edges, fix attrname typo

Co-authored-by: krivit <15682462+krivit@users.noreply.github.com>
…dges robustness

Co-authored-by: krivit <15682462+krivit@users.noreply.github.com>
Copilot AI changed the title [WIP] [statnet/ergm.multi-42] Simplify combined_networks structure Simplify combined_networks: list-based class with lazy block-diagonal construction Mar 15, 2026
Copilot AI requested a review from krivit March 15, 2026 06:28
@krivit krivit closed this Mar 15, 2026
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 this pull request may close these issues.

Simplify combined_networks structure?

2 participants