Skip to content

Feedforward block cannot detect parameters outside initial layer. #274

Description

@anthonyrtw

Describe the bug
Feedforward operations are useful in QML since it allows us to encode certain parameters conditional on certain measurements. Currently, FeedForwardBlock rejects any perceval Experiment with parameters encoded outside the initial layer.

To Reproduce

from merlin.algorithms import FeedForwardBlock
from perceval import *

experiment = Experiment(3)
experiment.add(0, Unitary.random(3))
experiment.with_input([1, 1, 0])
experiment.add(0, Detector.pnr())

x_param = P("x")

feedforward = FFCircuitProvider(1, 0, Circuit(2))
feedforward.add_configuration([0], BS(x_param) // BS(P("A")))
feedforward.add_configuration([1], BS(x_param) // BS(P("B")))
experiment.add(0, feedforward)

feedforward = FeedForwardBlock(
    experiment,
    trainable_parameters=["A", "B"],
    input_parameters=["x"]
)

Observed results
Immediate ValueError.

ValueError: The first stage must use all of the input parameters. Create you own stages with variable input parameters with the partial measurement strategy instead

Expected behavior
FeedForward block should be able to inspect all of the configurations in the feedforward configurator and detect all parameters.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions