Conversion Invariants
The ecosystem has adapters running in every direction — Network ↔ DynamicNetwork, DynamicNetwork → snapshots, contact sequences and relational-event sequences, Network → Siena panel matrices. Every one of them maps a rich source object onto a target that can hold less.
The dangerous failure mode is the implicit one: returning a plausible-looking object from which a field has quietly vanished. A snapshot of a partially observed network that reports zero unobserved dyads is not a snapshot — it is a fabrication, and every number computed from it is wrong in a way nothing downstream can detect.
So the ecosystem states one rule for conversions, mirroring the missing-data contract:
- Preserve what the target can represent. A field that can survive the trip must survive it. Silently dropping representable metadata is never acceptable.
- Reject or policy-gate what it cannot. A conversion whose target has no slot for a field either refuses the input, or drops the field under an explicit keyword the caller had to type. Missing-dyad masks are rejected by default (
missing=:error), because "unobserved" silently becoming "absent" is the exact failure the missing-data contract exists to prevent.missing=:faceis the auditable opt-in. - Report what was dropped. Every lossy conversion accepts
report=trueand then returns(result, ::ConversionReport)naming each dropped field and why.
using NetworkCore, DynamicNetworks
dnet = DynamicNetwork(4; observation_start=0.0, observation_end=10.0)
activate_vertices!(dnet, [1, 2, 3, 4], 0.0, 10.0)
activate!(dnet, 0.0, 8.0; edge=(1, 2))
snap, rep = network_extract(dnet, 5.0; report=true)
is_lossless(rep) # false — a snapshot has no time axis
dropped_fields(rep) # [:spells, :observation_period]
rep # pretty-prints each dropped field with its reasonThe invariant table
Legend: P preserved · T transformed (representable, but re-encoded) · D dropped, and named in the ConversionReport · R rejected unless an explicit policy is passed · — not applicable to this path.
| Field | Network→DynamicNetwork [1] | DynamicNetwork→Network [2] | DynamicNetwork→ContactSequence [3] | DynamicNetwork→EventSequence [4] | Network→Siena matrices [5] | Network↔Matrix [6] | Network→EgoData [7] | Networks→MultilayerNetwork [8] | Network→RankNetwork [9] |
|---|---|---|---|---|---|---|---|---|---|
| Directedness | P | P | P | T (undirected → (min,max) sender/receiver) | P | T (keyword on the way back) | R (undirected only; a directed input is an ArgumentError naming the symmetrisation) | P (every layer must match the first; checked) | R (directed only: rankings are ego-specific; an undirected input is refused) |
loops flag + self-loops | P | P | P | P | P (allow_self_loops) | T (keyword on the way back) | D, reported (:loops; the ego's own loop is never read, alter self-loops are not recorded) | P (combine_networks/split_by_layer carry the flag) | D, reported (:self_loops; the diagonal is ignored) |
| Vertex set / isolates | P | P (isolates kept; dropped only when retain_all_vertices=false and inactive) | P (n_vertices) | P (declared actor universe) | P (node-set size) | P | T (only the sampled egos and their alters; population_size = nv) | P (n checked per layer) | P |
| Vertex IDs | P | P, or T when retain_all_vertices=false (renumbered 1:k; originals in :vertex_pid) | P | P | P | P | P (alter IDs are vertex IDs) | P (actor a is vertex (l-1)·n + a in combine_networks) | P |
| Edge set | T (each edge gets one spell) | P | T (one Contact per spell) | T (one Event per spell onset) | P | P | T (ego–alter and alter–alter ties per ego; ties outside the sample D, reported as :edges when n_egos < nv) | P (combine_networks: within-block only; cross-block dyads structurally empty) | T (integer ranks read from the edge attribute attr=; every ordered pair must carry one, else R) |
| Vertex attributes | P | P | D | D | D | D (only :vertex_names, via names_eval) | T (only ego_attrs=; every other attribute D, reported as :vertex_attrs; an unknown or partially set ego_attrs entry is R) | P in the layers; D in combine_networks (which adds :layer/:actor), reported per attribute and layer | D, reported |
| Edge attributes | P | P | D | D | D | T (one attribute at a time, via attr=) | D, reported (:edge_attrs) | P in the layers; D in combine_networks, reported | D, reported (all but attr) |
| Network attributes | P | P | D | D | D | D | D, reported (:network_attrs) | D in combine_networks, reported | D, reported |
| Missing-dyad mask | P | P (remapped; entries on vertices dropped by retain_all_vertices=false are D) | R (missing=:error) | R (missing=:error) | R (missing=:error) | P with missing_value= / return_mask= + missing_mask=; D by default | R (missing=:error, via require_observed); P at face value under the written opt-in missing=:face, reported as :missing_dyads | P (as_multilayer stores the layers as given; combine_networks masks layer l's (i, j) at ((l-1)n+i, (l-1)n+j); split_by_layer remaps it back and R-ejects a masked cross-block dyad). No missing= keyword: the estimator ergm_multi refuses a masked layer | R (missing=:error only: an unobserved rank has no face value, so there is no :face) |
| Two-mode metadata | P | P, but D when retain_all_vertices=false (renumbering destroys the mode partition) | D | D | P (:twomode) | T (incidence matrix by default; expand_bipartite=true gives the square adjacency; flag not recoverable) | R (a Network with bipartite metadata or a BipartiteNetwork is refused) | R (add_layer!/as_multilayer refuse a two-mode layer: the within-layer dyad universe would enumerate the impossible within-mode pairs as observed non-ties) | R |
| Observation window | P (set to [onset, terminus)) | D | D | D | — | — | — | — | — |
| Spells (incl. overlapping) | T (one spell per element) | D (collapsed to presence/absence) | P (one contact per spell; overlaps stay separate) | D (only onsets survive; termini are not events) | — | — | — | — | — |
Point spells [t,t) | — | T (active exactly at t) | P (duration 0) | P (an event at t) | — | — | — | — | — |
| Spell censoring flags | — | D | D | D — onset-censored spells are skipped unless include_onset_censored=true | — | — | — | — | — |
| Time-varying (TEA) attributes | — | D | D | D | — | — | — | — | — |
| Actor presence / composition | P (all vertices active for the window) | D | D | D (the risk set is flat over time) | — | — | — | — | — |
Every adapter in the table now honours the contract: a mask is preserved, rejected, or read at face value only under a policy the caller typed, and every dropped field is named in a ConversionReport under report=true. (Before 0.2.0 the EgoData and MultilayerNetwork columns read the mask at face value with no keyword; see [10] for where the guards live now.)
Paths that are not their own conversion
Some packages do not author a conversion — they consume one, and inherit its row of the table wholesale:
- NDTV.jl renders snapshots via
network_extract(dnet, t; retain_all_vertices=true)(its_snapshot), so it inherits column 2 with stable vertex IDs. It computes layouts and never returns a network, so it has no invariants of its own. - TSNA.jl's point measures (
t_degree,t_betweenness, …) do the same. The snapshot they measure carries the missing-dyad mask, so whether a partially observed slice is refused depends on what each measure delegates to. Today six of them —t_degree,t_betweenness,t_closeness,t_transitivity,t_eigenvector,t_pagerank— refuse through SNA.jl'srequire_observed(with SNA's context name in the message), andt_densityand the:density/:mean_degree/:n_edgescolumns oft_sna_statsnow refuse throughNetworkCore.network_density(contextnetwork_density).t_reciprocity, the temporal-path family (earliest_arrival!,forward_reachable_set,temporal_path,reachability_matrix,temporal_distance),t_edge_duration,t_edge_formation/t_edge_dissolution,t_edge_persistence,t_turnoverandtie_decaystill compute at face value, and not_*measure exposes amissing=keyword. Giving everyt_*measure amissing::Symbol=:errorkeyword and one behaviour is planned; seeTSNA.jl/CHANGELOG.mdfor the status. - TSNA.jl's
t_aggregateisnetwork_collapseplus an aggregation rule (:union/:intersection/:weighted), and inherits column 2 exactly.
Why masked dyads are rejected, not coerced
A masked dyad is unobserved, not absent. Three of the five adapters target a representation with no way to say that:
- A
Contactis a tie that happened at a time. There is no contact meaning "we do not know whether this pair ever met." - An
Eventis an instant. Turning an unobserved dyad into a never-happened non-event biases the REM likelihood, which is conditional on the risk set. - A Siena matrix has its own mask — but it records structural zeros and ones, i.e. ties that are determined. Coding an unobserved dyad as a structural zero tells the estimator the tie is known to be impossible. That is a different, and false, claim.
None of these has a faithful encoding, so all three raise on a masked input:
julia> as_contact_sequence(dnet)
ERROR: ArgumentError: as_contact_sequence does not support missing (unobserved)
dyads, but the network has 2 masked dyads. A masked dyad is unobserved, not
absent, so reading its face value would silently invent data.
• pass `missing=:face` to analyse the stored face values anyway …The three ways forward are always the same: pass missing=:face to accept the face values in writing, call clear_missing_dyads! to declare the dyads observed, or use a routine that handles missingness (NetworkCore.supports_missing(f) == true).
Where the target can hold a mask — Network ↔ DynamicNetwork in both directions — it is carried, not dropped. An unobserved dyad of a base network is unobserved in every snapshot of it.
API
NetworkCore.ConversionReport — Type
ConversionReportMetadata describing what a conversion between network representations dropped.
Every lossy conversion in the ecosystem accepts a report::Bool=false keyword; with report=true it returns (result, ::ConversionReport) instead of just result. The report names the source and target representations and lists each dropped field with the reason it could not be carried across.
Fields
source::Symbol— the source representation (e.g.:DynamicNetwork)target::Symbol— the target representation (e.g.:Network)dropped::Vector{Pair{Symbol,String}}— dropped field ⇒ why
See also is_lossless, dropped_fields, record_drop!.
Example
# What an adapter builds (DynamicNetworks' `network_extract(dnet, t; report=true)`
# returns one of these beside the snapshot):
rep = ConversionReport(:DynamicNetwork, :Network)
record_drop!(rep, :spells, "a snapshot has no time axis")
record_drop!(rep, :observation_period, "a snapshot has no observation window")
is_lossless(rep) # false — a snapshot cannot carry spells
dropped_fields(rep) # [:spells, :observation_period]NetworkCore.record_drop! — Function
record_drop!(report::ConversionReport, field::Symbol, why::AbstractString) -> reportRecord that field could not be carried across a conversion, and why. Used by the conversion adapters to build their ConversionReport; calling it twice for the same field is not deduplicated.
Example
rep = ConversionReport(:DynamicNetwork, :Network)
record_drop!(rep, :spells, "a snapshot has no time axis")
is_lossless(rep) # false
dropped_fields(rep) # [:spells]NetworkCore.is_lossless — Function
is_lossless(report::ConversionReport) -> BoolWhether the conversion dropped nothing: every field of the source object is recoverable from the target.
Example
rep = ConversionReport(:Network, :Matrix)
is_lossless(rep) # true — nothing recorded yet
record_drop!(rep, :vertex_attrs, "a matrix has no vertex attributes")
is_lossless(rep) # falseNetworkCore.dropped_fields — Function
dropped_fields(report::ConversionReport) -> Vector{Symbol}The names of the fields the conversion dropped, in the order recorded.
Example
rep = ConversionReport(:Network, :Matrix)
record_drop!(rep, :vertex_attrs, "a matrix has no vertex attributes")
record_drop!(rep, :network_attrs, "a matrix has no network attributes")
dropped_fields(rep) # [:vertex_attrs, :network_attrs]- 1
DynamicNetworks.as_dynamic_network— lossless. ADynamicNetworkwraps aNetwork, so the whole source object is carried into it bycopy.network_collapse(as_dynamic_network(net))reproducesnet. - 2
DynamicNetworks.network_extract/network_collapse(andTSNA.t_aggregate, which isnetwork_collapseplus an aggregation rule).network_collapsekeeps vertex IDs stable, so it never hits theretain_all_verticescaveats. - 3
TSNA.as_contact_sequence. - 4
REM.EventSequence(::DynamicNetwork)(theREMDynamicNetworksExtextension). - 5
Siena.DependentNetwork/ConstantDyadCovariate/VaryingDyadCovariatefromNetworkwaves (theSienaNetworkExtextension). - 6
NetworkCore.as_matrix/network_from_matrix. See Missing Data for the lossless mask round-trip. - 7
ERGMEgo.simulate_ego_sample(net::Network, n_egos; ego_attrs, missing=:error, report=false, rng)— draws an egocentric sample from a complete network. It callsrequire_observed(net, missing; context="simulate_ego_sample")first (supports_missing == true,missing_policies == (:error, :face)), refuses directed and two-mode input and an unknown or partially setego_attrsentry, and withreport=truereturns(ed, ConversionReport(:Network, :EgoData))recording:edges,:vertex_attrs(one entry per unrequested attribute),:edge_attrs,:network_attrs,:loopsand, under:face,:missing_dyads; a census with every vertex attribute requested isis_lossless. Every cell is pinned by ERGMEgo's testset "Missing dyads and the conversion contract (simulateegosample)". - 8
ERGMMulti.as_multilayer(nets, names)/add_layer!(the layers are stored by identity, masks and attributes in place; a two-mode layer is refused),ERGMMulti.combine_networks(m; report)(the block-diagonalLayer()network: masks preserved at their block position,loopscarried, every layer vertex/edge/network attribute dropped and named in the report) andERGMMulti.split_by_layer(combined, n, L; report)(masks remapped back; a masked cross-block dyad is anArgumentError; the combined network's own attributes dropped and named).supports_missingistruefor all three; none takes amissing=keyword because there is nothing to opt into — the guard stays onergm_multi, which callsrequire_observed(layer; face_ok=false)on every layer. See ERGMMulti.jl's CHANGELOG, 0.2.0 Added, "The multilayer adapters honour the conversion contract". - 9
ERGMRank.as_rank_network(net::Network; attr=:rank, missing=:error, report=false)(and the matrix formas_rank_network(mat), which has no mask to guard).supports_missing == true,missing_policies == (:error,). Pinned by ERGMRank's testset "Network → RankNetwork adapter honours the conversion contract". - 10The two adapters that predated the contract gained
missing=/report=withrequire_observedand aConversionReportin 0.2.0 (see the ERGMEgo and ERGMMulti CHANGELOGs). A masked present-face dyad no longer becomes an observed alter–alter tie in anEgoData(refused, or reported undermissing=:face) nor an observed within-block tie in a combined network (masked there too).