Analyzer

The Analyzer algorithm aims at testing an Experiment, computing a probability table between input states and expected outputs, a performance score and an error rate, through a given Computer

For example, we call the Naive backend that we store in simulator_backend:

>>> simulator_backend = pcvl.BackendFactory().get_backend('Naive')

We can create an input state that will enter our optical scheme later on. We store it in input_state and use BasicState from the Perceval library.

>>> input_state = pcvl.BasicState("|1,1>")

let’s simulate the distribution obtained when we input two photons in a beam-splitter. We will use the Naive backend already stored in simulator_backend.

We will simulate the behavior of the circuit using the Analyzer which has four arguments:

  • The first one is an instance of the computer that we are going to use.

  • The second one is the experiment to analyse.

  • The third one is the input state (we will use input_state).

  • The fourth one is the desired output states. To compute all possible output states, one just input “*”.

>>> experiment = pcvl.Experiment(pcvl.BS())  # No need to declare the input state here
>>> computer = pcvl.SimulatedComputer(simulator_backend)
>>> with computer.acquire():
...     ca = pcvl.algorithm.Analyzer(computer, experiment, [input_state], "*")

Then, we display the result of Analyzer via pdisplay.

>>> pcvl.pdisplay(ca)
../../_images/CircuitAnalyzerHOM.png
class perceval.algorithm.analyzer.Analyzer(computer, experiment, input_states, output_states=None, mapping=None, **kwargs)

Analyzes a set of input states vs output states probabilities.

Parameters:
  • computer (AComputer) – the Computer on which to launch the tests

  • experiment (Experiment) – the Experiment to analyze

  • input_states (list[BasicState] | dict[BasicState, str]) – list of FockStates or a mapping {FockState: name}

  • output_states – list of output states. Valid values are: * None (then, the input states are taken as output states) * a list of FockState * a mapping {FockState: name} * the string “*” meaning oll possible target states are generated

  • mapping – optional mapping {FockState: name} used for display

  • kwargs – as the Analyzer internally uses an ExecutionFactory, it needs a “max_shots_per_call” value

col(output_state)

Return the column number for a given output state in the distribution matrix

Parameters:

output_state (BasicState) – any computed output state

Return type:

Optional[int]

Returns:

the column number, or None if the output state is unknown

compute(normalize=False, expected=None, progress_callback=None)

Iterate through the input states, generate (post-selected) output states and calculate distance with expected, if provided.

Parameters:
  • normalize (bool) – whether to normalize the output states

  • expected (Optional[dict]) – optional mapping between states in ideal case

  • progress_callback – optional callback to inform the user of the task progress

property distribution: Matrix

Return the truth table of the analysis. Computes it if wasn’t performed beforehand.

Returns:

a matrix containing the probabilities for each input vs output states