Skip to content

Commit

Permalink
function to compute fidelity
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiaanbrand committed Jul 22, 2024
1 parent 80faf61 commit 1b77037
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/qsylvan_simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,18 @@ qmdd_amp_from_prob(double a)
return weight_lookup(&c);
}

double qmdd_fidelity(QMDD a, QMDD b, BDDVAR nvars)
{
// c = <a|b>
AMP prod = aadd_inner_product(a, b, nvars);
complex_t c;
weight_value(prod, &c);

// fid = |c|^2 = |c.r + c.i|^2 = sqrt(c.r^2 + c.i^2)^2 = c.r^2 + c.i^2
double fid = c.r*c.r + c.i*c.i;
return fid;
}

/**********************</Measurements and probabilities>***********************/


Expand Down
5 changes: 5 additions & 0 deletions src/qsylvan_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ double qmdd_amp_to_prob(AMP a);
*/
AMP qmdd_amp_from_prob(double a);

/**
* Computes the fidelity |<a|b>|^2 for QMDDs a and b, both with nvars variables.
*/
double qmdd_fidelity(QMDD a, QMDD b, BDDVAR nvars);

/**********************</Measurements and probabilities>***********************/


Expand Down

0 comments on commit 1b77037

Please sign in to comment.