pasqal-io / qadence2-expressions

Qadence 2 expressions consisting of symbolic expressions and blocks, i.e. quantum digital, analog, digital-analog and composite gates, together with their logic and engine.
https://pasqal-io.github.io/qadence2-expressions/latest/
1 stars 0 forks source link

[Feature] Time-dependent block implementation #21

Open vytautas-a opened 4 months ago

vytautas-a commented 4 months ago

Current implementation of time-dependent block in qadence is using all the usual blocks to build the generator for HamEvo with two additional twists. First, the parameter that denotes time is a Parameter instance with an additional flag is_time=True. Currently it can be created using TimeParameter helper function in a similar way to FeatureParameter and VariationalParameter:

def TimeParameter(name: str) -> Parameter:
    """Shorthand for `Parameter(..., trainable=False, is_time=True)`."""
    return Parameter(name, trainable=False, is_time=True)

Second, the composite block acting as the generator has a property is_time_dependent=True (implemented in AbstractBlock class):

@property
def is_time_dependent(self) -> bool:
    from qadence.blocks.utils import parameters

    params: list[sympy.Basic] = parameters(self)
    return any(getattr(p, "is_time", False) for p in params)

Basically, that's all that distinguishes an arbitrary block from a time-dependent one.

kaosmicadei commented 4 months ago

How does it translate to PyQ?

RolandMacDoland commented 4 months ago

How does it translate to PyQ?

I think this is exactly what @vytautas-a is working on atm by implementing time-dependent solvers in PyQ.

kaosmicadei commented 4 months ago

From the expression side, it would require only a shortcut constructor.

def time_parameter(name: str) -> Expression:
    return Expression.symbol(name, time_parameter=True)

But it will not affect how the expressions handle that symbol.

From the platform side, we can add flags to the Alloc type in the Qadence IR similar to QuInstruct.

Then, a type symbol could be passed to the model as Alloc(1, trainable=True, time_parameter=True).

Regarding the operation, in addition to the prefix dyn_ in the operation's name (dyn_evo and dyn_qubit are the current suggestions), we can add a flag like time_dependent=True to t.