qrisp.QuantumVariable.custom#

classmethod QuantumVariable.custom(label_list, decoder=None, qs=None, name=None)[source]#

Creates a QuantumVariable with customized outcome labels.

Note that this is a class method, implying there is no need to create another QuantumVariable first to call this method.

Parameters:
label_listlist

A list of outcome labels.

decoderfunction, optional

The decoder function. If given none, the labels will be encoded according to their placement in the label_list.

qsQuantumSession, optional

The QuantumSession in which to register the customized QuantumVariable. If given none, the QuantumVariable will be registered in a new QuantumSession.

namestring, optional

The name of the QuantumVariable. If given none, a suited name will be generated.

Returns:
CustomQuantumVariable

A QuantumVariable with the desired outcome labels.

Examples

We create a QuantumVariable with some examples values as outcome labels and bring it into uniform superposition.

>>> from qrisp import QuantumVariable, h
>>> qv = QuantumVariable.custom(["lorem", "ipsum", "dolor", "sit", 42, (1,2,3)])
>>> h(qv)
>>> print(qv)
{'lorem': 0.125, 'ipsum': 0.125, 'dolor': 0.125, 'sit': 0.125, 42: 0.125,
(1, 2, 3): 0.125, 'undefined_label_6': 0.125, 'undefined_label_7': 0.125}