uiharu-core 0.1.0

The runtime of the uiharu streaming protocol decode engine
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
// SPDX-License-Identifier: Apache-2.0

//! Building a decode graph: sources of logic samples, decoder nodes, the connections between
//! their typed ports and the outputs exposed to the caller. Connecting checks that the ports
//! agree on the schema and that the input's requirements are met; building checks that every
//! input is connected, that the graph has no cycle and that each node reads one time domain.

use std::collections::{BTreeSet, VecDeque};
use std::fmt;
use std::marker::PhantomData;
use std::sync::Arc;

use crate::exec::Pipeline;
use crate::node::{Node, NodeSpec};
use crate::schema::{InputSpec, OutputSpec, Props, SchemaId};
use crate::signal::{LogicBlock, MAX_CHANNELS};
use crate::time::TimeBase;

/// A source of logic samples in a graph.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct SourceId(pub(crate) usize);

impl SourceId {
    /// The source added `index`-th to its graph.
    pub const fn from_index(index: usize) -> Self {
        Self(index)
    }

    /// The source's position among the graph's sources.
    pub const fn index(self) -> usize {
        self.0
    }
}

/// A node in a graph.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct NodeId(pub(crate) usize);

impl NodeId {
    /// The node added `index`-th to its graph.
    pub const fn from_index(index: usize) -> Self {
        Self(index)
    }

    /// The node's position among the graph's nodes.
    pub const fn index(self) -> usize {
        self.0
    }
}

/// Who owns an output port.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) enum Owner {
    Source(usize),
    Node(usize),
}

/// An output port of a source or node.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) struct PortKey {
    pub(crate) owner: Owner,
    pub(crate) index: usize,
}

/// An output port carrying `T` events, as [`Graph::connect`] and [`Graph::expose`] take it.
pub struct OutputRef<T> {
    key: PortKey,
    _payload: PhantomData<fn() -> T>,
}

impl<T> OutputRef<T> {
    /// Output port `index` of `node`. The node's own helpers build these, as only the node
    /// knows the payload types of its ports.
    pub fn of_node(node: NodeId, index: usize) -> Self {
        Self {
            key: PortKey {
                owner: Owner::Node(node.0),
                index,
            },
            _payload: PhantomData,
        }
    }
}

impl<T> Clone for OutputRef<T> {
    fn clone(&self) -> Self {
        *self
    }
}

impl<T> Copy for OutputRef<T> {}

impl<T> fmt::Debug for OutputRef<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("OutputRef").field("key", &self.key).finish()
    }
}

/// An input port reading `T` events.
pub struct InputRef<T> {
    node: usize,
    index: usize,
    _payload: PhantomData<fn() -> T>,
}

impl<T> InputRef<T> {
    /// Input port `index` of `node`; see [`OutputRef::of_node`].
    pub fn of_node(node: NodeId, index: usize) -> Self {
        Self {
            node: node.0,
            index,
            _payload: PhantomData,
        }
    }
}

impl<T> Clone for InputRef<T> {
    fn clone(&self) -> Self {
        *self
    }
}

impl<T> Copy for InputRef<T> {}

impl<T> fmt::Debug for InputRef<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("InputRef")
            .field("node", &self.node)
            .field("index", &self.index)
            .finish()
    }
}

/// An exposed output, read through [`Pipeline::exposed`].
pub struct ExposedRef<T> {
    pub(crate) index: usize,
    _payload: PhantomData<fn() -> T>,
}

impl<T> Clone for ExposedRef<T> {
    fn clone(&self) -> Self {
        *self
    }
}

impl<T> Copy for ExposedRef<T> {}

impl<T> fmt::Debug for ExposedRef<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("ExposedRef")
            .field("index", &self.index)
            .finish()
    }
}

/// An output port named at run time, for graphs built from a description rather than from
/// typed code; see [`Graph::output`] and [`Graph::connect_dyn`].
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct DynOutput {
    key: PortKey,
}

/// An input port named at run time; see [`Graph::input`].
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct DynInput {
    node: usize,
    index: usize,
}

/// An output exposed through [`Graph::expose_dyn`], read with [`Pipeline::exposed_dyn`].
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct DynExposedRef {
    pub(crate) index: usize,
}

/// A source of logic samples, as [`Graph::source`] takes it.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SourceSpec {
    /// The source's name, for diagnostics and statistics.
    pub name: String,
    /// Its channels, at most [`MAX_CHANNELS`].
    pub channels: u8,
    /// Its clock.
    pub time_base: TimeBase,
    /// The blocks the source holds for its readers before [`Pipeline::push`] reports it full.
    pub capacity: usize,
}

impl SourceSpec {
    /// A source named `name` with `channels` channels on `time_base`, holding four blocks.
    pub fn new(name: impl Into<String>, channels: u8, time_base: TimeBase) -> Self {
        Self {
            name: name.into(),
            channels,
            time_base,
            capacity: 4,
        }
    }

    /// Sets how many blocks the source holds.
    pub fn with_capacity(mut self, capacity: usize) -> Self {
        self.capacity = capacity.max(1);
        self
    }

    pub(crate) fn output(&self) -> OutputSpec {
        OutputSpec::new::<Arc<LogicBlock>>(
            "samples",
            Props::new()
                .with("channels", i64::from(self.channels))
                .with(
                    "rateHz",
                    i64::try_from(self.time_base.rate_hz).unwrap_or(i64::MAX),
                ),
        )
    }
}

/// The source as added to a graph: its id and its output.
#[derive(Clone, Copy, Debug)]
pub struct SourceHandle {
    /// The source.
    pub id: SourceId,
    /// Its blocks of samples.
    pub samples: OutputRef<Arc<LogicBlock>>,
}

/// Limits every node and queue of a graph shares.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct GraphConfig {
    /// Items a queue between nodes holds before the writer waits.
    pub queue_capacity: usize,
    /// Operations a node completes in one poll before it yields to the others.
    pub budget: u32,
}

impl Default for GraphConfig {
    fn default() -> Self {
        Self {
            queue_capacity: 256,
            budget: 1024,
        }
    }
}

/// Why a graph cannot be built as asked.
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
pub enum GraphError {
    /// A port reference names a node the graph does not have.
    #[error("no node {0} in the graph")]
    UnknownNode(usize),
    /// A port reference names a port its owner does not declare.
    #[error("{owner} declares no {direction} port {index}")]
    UnknownPort {
        /// The source or node.
        owner: String,
        /// `input` or `output`.
        direction: &'static str,
        /// The port index.
        index: usize,
    },
    /// A source has more channels than a block can hold.
    #[error("source {name} has {channels} channels; at most {MAX_CHANNELS} are supported")]
    TooManyChannels {
        /// The source.
        name: String,
        /// Its channels.
        channels: u8,
    },
    /// The output and the input do not carry the same schema.
    #[error("{from} carries {output} but {to} reads {input}")]
    SchemaMismatch {
        /// The output port.
        from: String,
        /// The input port.
        to: String,
        /// The output's schema.
        output: SchemaId,
        /// The input's schema.
        input: SchemaId,
    },
    /// The output does not satisfy a requirement of the input.
    #[error("{to} requires {key} {requirement} of {from}, which declares {found}")]
    Requirement {
        /// The output port.
        from: String,
        /// The input port.
        to: String,
        /// The property.
        key: &'static str,
        /// What the input requires.
        requirement: String,
        /// What the output declares, or `nothing`.
        found: String,
    },
    /// The input is already connected; an input reads one output.
    #[error("{to} is already connected")]
    AlreadyConnected {
        /// The input port.
        to: String,
    },
    /// The input is not connected.
    #[error("{to} is not connected")]
    Unconnected {
        /// The input port.
        to: String,
    },
    /// The graph has a cycle through this node.
    #[error("{node} is part of a cycle")]
    Cycle {
        /// The node.
        node: String,
    },
    /// The node reads inputs from different sources.
    #[error("{node} reads from more than one time domain ({first} and {second})")]
    TimeDomain {
        /// The node.
        node: String,
        /// A source it reads.
        first: String,
        /// Another source it reads.
        second: String,
    },
    /// Two exposed outputs share a name.
    #[error("an output named {0} is already exposed")]
    DuplicateExposure(String),
    /// A port named at run time does not exist.
    #[error("{owner} has no {direction} port named {name}")]
    UnknownPortName {
        /// The source or node.
        owner: String,
        /// `input` or `output`.
        direction: &'static str,
        /// The name asked for.
        name: String,
    },
}

struct NodeEntry {
    node: Box<dyn Node>,
    spec: NodeSpec,
    /// What each input reads, once connected.
    inputs: Vec<Option<PortKey>>,
}

pub(crate) struct Exposure {
    pub(crate) name: String,
    pub(crate) from: PortKey,
}

/// A decode graph under construction.
pub struct Graph {
    config: GraphConfig,
    sources: Vec<SourceSpec>,
    nodes: Vec<NodeEntry>,
    exposed: Vec<Exposure>,
}

impl fmt::Debug for Graph {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Graph")
            .field("config", &self.config)
            .field("sources", &self.sources.len())
            .field("nodes", &self.nodes.len())
            .field("exposed", &self.exposed.len())
            .finish()
    }
}

impl Default for Graph {
    fn default() -> Self {
        Self::new()
    }
}

impl Graph {
    /// An empty graph with the default limits.
    pub fn new() -> Self {
        Self::with_config(GraphConfig::default())
    }

    /// An empty graph with `config`'s limits.
    pub fn with_config(config: GraphConfig) -> Self {
        Self {
            config,
            sources: Vec::new(),
            nodes: Vec::new(),
            exposed: Vec::new(),
        }
    }

    /// The graph's limits.
    pub fn config(&self) -> GraphConfig {
        self.config
    }

    /// Adds a source of logic samples.
    pub fn source(&mut self, spec: SourceSpec) -> Result<SourceHandle, GraphError> {
        if spec.channels > MAX_CHANNELS {
            return Err(GraphError::TooManyChannels {
                name: spec.name,
                channels: spec.channels,
            });
        }
        let id = SourceId(self.sources.len());
        self.sources.push(spec);
        Ok(SourceHandle {
            id,
            samples: OutputRef {
                key: PortKey {
                    owner: Owner::Source(id.0),
                    index: 0,
                },
                _payload: PhantomData,
            },
        })
    }

    /// Adds a node.
    pub fn add(&mut self, node: impl Node) -> NodeId {
        let spec = node.spec();
        let inputs = vec![None; spec.inputs.len()];
        self.nodes.push(NodeEntry {
            node: Box::new(node),
            spec,
            inputs,
        });
        NodeId(self.nodes.len() - 1)
    }

    fn owner_name(&self, owner: Owner) -> String {
        match owner {
            Owner::Source(index) => {
                format!(
                    "{}#{index}",
                    self.sources.get(index).map_or("?", |s| s.name.as_str())
                )
            }
            Owner::Node(index) => {
                format!(
                    "{}#{index}",
                    self.nodes.get(index).map_or("?", |n| n.spec.name.as_str())
                )
            }
        }
    }

    fn output_spec(&self, key: PortKey) -> Result<OutputSpec, GraphError> {
        let unknown = || GraphError::UnknownPort {
            owner: self.owner_name(key.owner),
            direction: "output",
            index: key.index,
        };
        match key.owner {
            Owner::Source(index) => {
                let source = self.sources.get(index).ok_or_else(unknown)?;
                if key.index != 0 {
                    return Err(unknown());
                }
                Ok(source.output())
            }
            Owner::Node(index) => {
                let node = self
                    .nodes
                    .get(index)
                    .ok_or(GraphError::UnknownNode(index))?;
                node.spec
                    .outputs
                    .get(key.index)
                    .cloned()
                    .ok_or_else(unknown)
            }
        }
    }

    fn input_spec(&self, node: usize, index: usize) -> Result<&InputSpec, GraphError> {
        let entry = self.nodes.get(node).ok_or(GraphError::UnknownNode(node))?;
        entry
            .spec
            .inputs
            .get(index)
            .ok_or_else(|| GraphError::UnknownPort {
                owner: self.owner_name(Owner::Node(node)),
                direction: "input",
                index,
            })
    }

    fn port_name(&self, owner: Owner, name: &str) -> String {
        format!("{}.{name}", self.owner_name(owner))
    }

    /// Connects an output to an input, checking that they carry the same schema and that the
    /// output satisfies what the input requires.
    pub fn connect<T>(&mut self, from: OutputRef<T>, to: InputRef<T>) -> Result<(), GraphError> {
        self.connect_keys(from.key, to.node, to.index)
    }

    /// Exposes an output under `name`, to be read from the pipeline.
    pub fn expose<T>(
        &mut self,
        name: impl Into<String>,
        from: OutputRef<T>,
    ) -> Result<ExposedRef<T>, GraphError> {
        let index = self.expose_key(name.into(), from.key)?;
        Ok(ExposedRef {
            index,
            _payload: PhantomData,
        })
    }

    /// The samples output of `source`, for a graph built from a description.
    pub fn source_output(&self, source: SourceId) -> Result<DynOutput, GraphError> {
        if source.0 >= self.sources.len() {
            return Err(GraphError::UnknownPort {
                owner: self.owner_name(Owner::Source(source.0)),
                direction: "output",
                index: 0,
            });
        }
        Ok(DynOutput {
            key: PortKey {
                owner: Owner::Source(source.0),
                index: 0,
            },
        })
    }

    /// Output port `name` of `node`, for a graph built from a description.
    pub fn output(&self, node: NodeId, name: &str) -> Result<DynOutput, GraphError> {
        let entry = self
            .nodes
            .get(node.0)
            .ok_or(GraphError::UnknownNode(node.0))?;
        let index = entry
            .spec
            .outputs
            .iter()
            .position(|output| output.name == name)
            .ok_or_else(|| GraphError::UnknownPortName {
                owner: self.owner_name(Owner::Node(node.0)),
                direction: "output",
                name: name.to_owned(),
            })?;
        Ok(DynOutput {
            key: PortKey {
                owner: Owner::Node(node.0),
                index,
            },
        })
    }

    /// Input port `name` of `node`, for a graph built from a description.
    pub fn input(&self, node: NodeId, name: &str) -> Result<DynInput, GraphError> {
        let entry = self
            .nodes
            .get(node.0)
            .ok_or(GraphError::UnknownNode(node.0))?;
        let index = entry
            .spec
            .inputs
            .iter()
            .position(|input| input.name == name)
            .ok_or_else(|| GraphError::UnknownPortName {
                owner: self.owner_name(Owner::Node(node.0)),
                direction: "input",
                name: name.to_owned(),
            })?;
        Ok(DynInput {
            node: node.0,
            index,
        })
    }

    /// Connects ports named at run time, with the checks of [`Graph::connect`]; the schema
    /// check is what keeps the event types straight here.
    pub fn connect_dyn(&mut self, from: DynOutput, to: DynInput) -> Result<(), GraphError> {
        self.connect_keys(from.key, to.node, to.index)
    }

    /// Exposes an output named at run time under `name`.
    pub fn expose_dyn(
        &mut self,
        name: impl Into<String>,
        from: DynOutput,
    ) -> Result<DynExposedRef, GraphError> {
        Ok(DynExposedRef {
            index: self.expose_key(name.into(), from.key)?,
        })
    }

    /// The schema of the output behind a port named at run time.
    pub fn schema_of(&self, output: DynOutput) -> Result<SchemaId, GraphError> {
        self.output_spec(output.key).map(|spec| spec.schema)
    }

    /// The properties the output behind a port named at run time declares.
    pub fn props_of(&self, output: DynOutput) -> Result<Props, GraphError> {
        self.output_spec(output.key).map(|spec| spec.props)
    }

    fn connect_keys(&mut self, from: PortKey, node: usize, index: usize) -> Result<(), GraphError> {
        let output = self.output_spec(from)?;
        let input = self.input_spec(node, index)?.clone();
        let from_name = self.port_name(from.owner, output.name);
        let to_name = self.port_name(Owner::Node(node), input.name);
        if output.schema != input.schema {
            return Err(GraphError::SchemaMismatch {
                from: from_name,
                to: to_name,
                output: output.schema,
                input: input.schema,
            });
        }
        if let Some((key, requirement)) = input.requires.unmet(&output.props) {
            let found = output
                .props
                .get(key)
                .map_or_else(|| "nothing".to_owned(), |v| v.to_string());
            let requirement = requirement.to_string();
            return Err(GraphError::Requirement {
                from: from_name,
                to: to_name,
                key,
                requirement,
                found,
            });
        }
        let slot = &mut self.nodes[node].inputs[index];
        if slot.is_some() {
            return Err(GraphError::AlreadyConnected { to: to_name });
        }
        *slot = Some(from);
        Ok(())
    }

    fn expose_key(&mut self, name: String, from: PortKey) -> Result<usize, GraphError> {
        self.output_spec(from)?;
        if self.exposed.iter().any(|exposure| exposure.name == name) {
            return Err(GraphError::DuplicateExposure(name));
        }
        self.exposed.push(Exposure { name, from });
        Ok(self.exposed.len() - 1)
    }

    /// The nodes in an order where every node comes after the ones it reads.
    fn order(&self) -> Result<Vec<usize>, GraphError> {
        let mut pending: Vec<usize> = self
            .nodes
            .iter()
            .map(|entry| {
                entry
                    .inputs
                    .iter()
                    .filter(|input| {
                        matches!(
                            input,
                            Some(PortKey {
                                owner: Owner::Node(_),
                                ..
                            })
                        )
                    })
                    .count()
            })
            .collect();
        let mut ready: VecDeque<usize> = (0..self.nodes.len())
            .filter(|&node| pending[node] == 0)
            .collect();
        let mut order = Vec::with_capacity(self.nodes.len());
        while let Some(node) = ready.pop_front() {
            order.push(node);
            for (next, entry) in self.nodes.iter().enumerate() {
                let reads = entry
                    .inputs
                    .iter()
                    .filter(|input| matches!(input, Some(PortKey { owner: Owner::Node(n), .. }) if *n == node))
                    .count();
                if reads > 0 {
                    pending[next] -= reads;
                    if pending[next] == 0 {
                        ready.push_back(next);
                    }
                }
            }
        }
        if order.len() < self.nodes.len() {
            let stuck = (0..self.nodes.len())
                .find(|node| !order.contains(node))
                .unwrap_or(0);
            return Err(GraphError::Cycle {
                node: self.owner_name(Owner::Node(stuck)),
            });
        }
        Ok(order)
    }

    /// The time domain (source) of each node, in `order`.
    fn domains(&self, order: &[usize]) -> Result<Vec<Option<usize>>, GraphError> {
        let mut domains: Vec<Option<usize>> = vec![None; self.nodes.len()];
        for &node in order {
            let mut domain: Option<usize> = None;
            for input in self.nodes[node].inputs.iter().flatten() {
                let read = match input.owner {
                    Owner::Source(source) => Some(source),
                    Owner::Node(upstream) => domains[upstream],
                };
                match (domain, read) {
                    (Some(first), Some(second)) if first != second => {
                        return Err(GraphError::TimeDomain {
                            node: self.owner_name(Owner::Node(node)),
                            first: self.owner_name(Owner::Source(first)),
                            second: self.owner_name(Owner::Source(second)),
                        });
                    }
                    (None, Some(read)) => domain = Some(read),
                    _ => {}
                }
            }
            domains[node] = domain;
        }
        Ok(domains)
    }

    /// Checks the graph and starts its nodes.
    pub fn build(self) -> Result<Pipeline, GraphError> {
        for (index, entry) in self.nodes.iter().enumerate() {
            for (port, input) in entry.inputs.iter().enumerate() {
                if input.is_none() {
                    return Err(GraphError::Unconnected {
                        to: self.port_name(Owner::Node(index), entry.spec.inputs[port].name),
                    });
                }
            }
        }
        let order = self.order()?;
        let domains = self.domains(&order)?;
        // What each input reads: the properties of the output behind it.
        let input_props: Vec<Vec<Props>> = self
            .nodes
            .iter()
            .map(|entry| {
                entry
                    .inputs
                    .iter()
                    .flatten()
                    .map(|key| self.output_spec(*key).map(|spec| spec.props))
                    .collect::<Result<Vec<_>, _>>()
            })
            .collect::<Result<_, _>>()?;
        let mut exposed_names = BTreeSet::new();
        for exposure in &self.exposed {
            if !exposed_names.insert(exposure.name.as_str()) {
                return Err(GraphError::DuplicateExposure(exposure.name.clone()));
            }
        }
        let Graph {
            config,
            sources,
            nodes,
            exposed,
        } = self;
        let (nodes, specs, inputs): (Vec<_>, Vec<_>, Vec<_>) = nodes
            .into_iter()
            .map(|entry| (entry.node, entry.spec, entry.inputs))
            .fold(
                (Vec::new(), Vec::new(), Vec::new()),
                |mut acc, (node, spec, input)| {
                    acc.0.push(node);
                    acc.1.push(spec);
                    acc.2.push(input);
                    acc
                },
            );
        Pipeline::start(
            config,
            sources,
            nodes,
            specs,
            inputs,
            order,
            domains,
            input_props,
            exposed,
        )
    }
}