Skip to content

Adapter

inspeqtor.models.adapter

inspeqtor.models.adapter.observable_to_expvals

observable_to_expvals(
    output, unitaries: ndarray
) -> ndarray

Function to be used with Wo-based model for probabilistic model construction with make_probabilistic_model function.

Parameters:

Name Type Description Default
output Any

The output from Wo-based model

required
unitaries ndarray

Ideal unitary, ignore in this function.

required

Returns:

Type Description
ndarray

jnp.ndarray: Expectation values array

Source code in src/inspeqtor/v1/model.py
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
def observable_to_expvals(output, unitaries: jnp.ndarray) -> jnp.ndarray:
    """Function to be used with Wo-based model for probabilistic model construction
    with `make_probabilistic_model` function.

    Args:
        output (typing.Any): The output from Wo-based model
        unitaries (jnp.ndarray): Ideal unitary, ignore in this function.

    Returns:
        jnp.ndarray: Expectation values array
    """
    return get_predict_expectation_value(
        observable=output,
        unitaries=unitaries,
        evaluate_expectation_values=default_expectation_values_order,
    )

inspeqtor.models.adapter.unitary_to_expvals

unitary_to_expvals(output, unitaries: ndarray) -> ndarray

Function to be used with Unitary-based model for probabilistic model construction with make_probabilistic_model function.

Parameters:

Name Type Description Default
output Any

The output from Unitary-based model

required
unitaries ndarray

Ideal unitary, ignore in this function.

required

Returns:

Type Description
ndarray

jnp.ndarray: Expectation values array

Source code in src/inspeqtor/v1/model.py
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
def unitary_to_expvals(output, unitaries: jnp.ndarray) -> jnp.ndarray:
    """Function to be used with Unitary-based model for probabilistic model construction
    with `make_probabilistic_model` function.



    Args:
        output (typing.Any): The output from Unitary-based model
        unitaries (jnp.ndarray): Ideal unitary, ignore in this function.

    Returns:
        jnp.ndarray: Expectation values array
    """
    U = unitary(output)
    return get_predict_expectation_value(
        {
            "X": jnp.broadcast_to(X, shape=(U.shape)),
            "Y": jnp.broadcast_to(Y, shape=(U.shape)),
            "Z": jnp.broadcast_to(Z, shape=(U.shape)),
        },
        U,
        default_expectation_values_order,
    )

inspeqtor.models.adapter.toggling_unitary_to_expvals

toggling_unitary_to_expvals(
    output: ndarray, unitaries: ndarray
) -> ndarray

Calculate \(U_J\) and convert it to expectation values.

Parameters:

Name Type Description Default
output ndarray

Parameters parametrized unitary operator

required
unitaries ndarray

Ideal unitary operators corresponding to the output

required

Returns:

Type Description
ndarray

jnp.ndarray: Predicted expectation values

Source code in src/inspeqtor/v1/model.py
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
def toggling_unitary_to_expvals(
    output: jnp.ndarray, unitaries: jnp.ndarray
) -> jnp.ndarray:
    """Calculate $U_J$ and convert it to expectation values.

    Args:
        output (jnp.ndarray): Parameters parametrized unitary operator
        unitaries (jnp.ndarray): Ideal unitary operators corresponding to the output

    Returns:
        jnp.ndarray: Predicted expectation values
    """
    UJ: jnp.ndarray = unitary(output)  # type: ignore
    UJ_dagger = jnp.swapaxes(UJ, -2, -1).conj()

    X_ = UJ_dagger @ X @ UJ
    Y_ = UJ_dagger @ Y @ UJ
    Z_ = UJ_dagger @ Z @ UJ

    return get_predict_expectation_value(
        {"X": X_, "Y": Y_, "Z": Z_},
        unitaries,
        default_expectation_values_order,
    )