Bug regarding parameter assignment for processors

Hi,
I think there might be a bug regarding parameter assignment in processors. I am working off perceval version: 0.11.0.post2.
I’ll give an example:

import perceval as pcvl
import perceval.components.unitary_components as comp
from perceval import Processor, P
from perceval.algorithm import Sampler

processor = Processor("SLOS", 2)
processor.add(0, comp.PS(P("A")))
processor.add(0, comp.BS.H())
processor.set_parameters({"A": 0.5})
processor.with_input(pcvl.BasicState([1, 0]))

sampler = Sampler(processor)
results = sampler.sample_count(100)['results']

print(results)

And I receive the warning/error:

UserWarning: An exception was raised during job execution.
<class 'AssertionError'>: All parameters must be defined to compute numeric unitary matrix
  warnings.warn(f"An exception was raised during job execution.\n{type(e)}: {e}")

This suggests that the parameter “A” was not assigned the value specified. I can verify this by doing:

processor.get_circuit_parameters()

which returns:

{'A': Parameter(name='A', value=None, min_v=0.0, max_v=6.283185307179586)}

Hello,

In a Processor, there are two layers of parameters.

  • The processor-related parameters which are mainly used to pass specific configuration in case of remote processors (as all platforms on Quandela Cloud do not have exactly the same features)
  • The circuit-level parameters. A processor contains a linear-optics circuit that can contain variable floating point parameters.

Calling set_parameters sets a processor-level parameter.
Calling get_circuit_parameters retrieves all circuit-level parameters.

However, I understand the misunderstanding. We’ll need to document this better, or even change some namings.

What I suggest is you either keep an instance of P("A") so that you can set a value later on.

param_A = P("A")
processor = Processor("SLOS", 2)
processor.add(0, comp.PS(param_A))

# ...

param_A.set_value(0.5)

If the structure of your program prevents that, you can always use get_circuit_parameters to act on the numerical value of every parameter

params = processor.get_circuit_parameters()
params['A'].set_value(0.5)

Best wishes,
Eric

Thanks for your help, Eric!

I ended up using processor.linear_circuit().assign({"A": 0.5}) and it seems to also work well.

Best,
Anthony