Skip to content

Commit

Permalink
[pyschlandals] get output of distribution nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreDubray committed Sep 22, 2023
1 parent 1ded010 commit dd97b49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pyschlandals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ impl PyDac {
self.dac.get_distribution_domain_size(DistributionNodeIndex(distribution))
}

/// Returns the pair (circuit node, value index) of the output of the distribution at its given output-index
pub fn get_distribution_node_output_at(&self, distribution: usize, index: usize) -> (usize, usize) {
let x = self.dac.get_distribution_output_at(DistributionNodeIndex(distribution), index);
(x.0.0, x.1)
}

/// Returns the probability, of the given distribution, at the given index
pub fn get_distribution_probability(&self, distribution: usize, probability_index: usize) -> f64 {
self.dac.get_distribution_probability_at(DistributionNodeIndex(distribution), probability_index)
Expand Down
8 changes: 7 additions & 1 deletion src/compiler/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct CircuitNode {
/// A distribution node, an input of the circuit. Each distribution node holds the distribution's parameter as well as the outputs.
/// For each output node, it also stores the value that must be sent to the output (as an index of the probability vector).
struct DistributionNode {

/// Probabilities of the distribution
probabilities: Vec<f64>,
/// Outputs of the node
Expand Down Expand Up @@ -157,7 +158,7 @@ impl Dac {

/// Adds `output` to the outputs of `node` and `node` to the inputs of `output`. Note that this
/// function uses the vectors in each node. They are transferred afterward in the `outputs` vector.
pub fn add_spnode_output(&mut self, node: CircuitNodeIndex, output: CircuitNodeIndex) {
pub fn add_circuit_node_output(&mut self, node: CircuitNodeIndex, output: CircuitNodeIndex) {
self.nodes[node.0].outputs.push(output);
self.nodes[node.0].number_outputs += 1;
self.nodes[output.0].inputs.insert(node);
Expand Down Expand Up @@ -509,6 +510,11 @@ impl Dac {
self.distribution_nodes[distribution.0].probabilities[index]
}

/// Returns the pair (circuit_node, index) for the output of the distribution at the given index
pub fn get_distribution_output_at(&self, distribution: DistributionNodeIndex, index: usize) -> (CircuitNodeIndex, usize) {
self.distribution_nodes[distribution.0].outputs[index]
}

// --- SETTERS --- //

/// Set the probability of the distribution, at the given index, to the given value
Expand Down

0 comments on commit dd97b49

Please sign in to comment.