Download Notebook

StateEnsemble and state_ensemble_typical

[1]:
import numpy as np
np.set_printoptions(linewidth=200)

StateEnsemble

StateEnsemble is a list of State with corresponding probabilities(MultinomialDistribution).
The property states is a list of State. The property ps is probabilities.
Example.
If StateEnsemble is a ensemble of \((1/2, z_0)\) and \((1/2, z_1)\), then states = \([z_0, z_1]\) and ps = MultinomialDistribution of \([1/2, 1/2]\).

The methods for generating a StateEnsemble includes the following:

  • Generate from state_ensemble_typical module

  • Generate StateEnsemble object directly

Generate from state_ensemble_typical module by specifying CompositeSystem and state name (ex. “z0”).

[2]:
from quara.objects.composite_system_typical import generate_composite_system
from quara.objects.state_ensemble_typical import generate_state_ensemble_from_name

c_sys = generate_composite_system("qubit", 1)
ensemble = generate_state_ensemble_from_name(c_sys, "z0")
print(ensemble)
Type:
StateEnsemble

States:
states[0]: [0.70710678 0.         0.         0.70710678]
states[1]: [ 0.70710678  0.          0.         -0.70710678]

MultinomialDistribution:
shape = (2,)
ps = [1. 0.]

Generate StateEnsemble object directly using a list of State and MultinomialDistribution.

[3]:
from quara.objects.composite_system import CompositeSystem
from quara.objects.elemental_system import ElementalSystem
from quara.objects.matrix_basis import get_normalized_pauli_basis
from quara.objects.state import State
from quara.objects.multinomial_distribution import MultinomialDistribution
from quara.objects.state_ensemble import StateEnsemble

basis = get_normalized_pauli_basis(1)
e_sys = ElementalSystem(0, basis)
c_sys = CompositeSystem([e_sys])
vec1 = np.array([1, 0, 0, 1]) / np.sqrt(2)
state1 = State(c_sys, vec1)
vec2 = np.array([1, 0, 0, -1]) / np.sqrt(2)
state2 = State(c_sys, vec2)

ps = [1.0, 0.0]
dist = MultinomialDistribution(ps)
ensemble = StateEnsemble([state1, state2], dist)
print(ensemble)
Type:
StateEnsemble

States:
states[0]: [0.70710678 0.         0.         0.70710678]
states[1]: [ 0.70710678  0.          0.         -0.70710678]

MultinomialDistribution:
shape = (2,)
ps = [1. 0.]

specific properties

The property vec of states is a list of State specified by the constructor argument states.

[4]:
ensemble = StateEnsemble([state1, state2], dist)
print(f"states: \n{ensemble.states}")
states:
[<quara.objects.state.State object at 0x000001E734C6F8C8>, <quara.objects.state.State object at 0x000001E734C6FFC8>]

The state() function returns a State specified by the constructor argument state.

[5]:
ensemble = StateEnsemble([state1, state2], dist)
print(f"state(0): \n{ensemble.state(0)}")
print(f"state(1): \n{ensemble.state(1)}")
state(0):
Type:
State

Dim:
2

Vec:
[0.70710678 0.         0.         0.70710678]
state(1):
Type:
State

Dim:
2

Vec:
[ 0.70710678  0.          0.         -0.70710678]

The property vec of prob_dist is a MultinomialDistribution specified by the constructor argument prob_dist.

[6]:
ensemble = StateEnsemble([state1, state2], dist)
print(f"prob_dist: {ensemble.prob_dist}")
prob_dist: shape = (2,)
ps = [1. 0.]

other functions

Many functions that other subclasses of QOperation have are not supported in StateEnsemble. If an unsupported function is executed, a NotImplementedError will be raised.

state_ensemble_typical

generate_state_ensemble_object_from_state_ensemble_name_object_name() function in state_ensemble_typical module can easily generate objects related to MProcess.
The generate_state_ensemble_object_from_state_ensemble_name_object_name() function has the following arguments:
  • The string that can be specified for mprocess_name can be checked by executing the get_state_ensemble_names() function. The tensor product of state_ensemble_names “a”, “b” is written “a_b”.

  • object_name can be the following string:

  • “state_ensemble” - StateEnsemble object.

  • c_sys - CompositeSystem of objects related to MProcess. Specify when object_name is “state_ensemble”.

  • is_physicality_required - Whether the generated object is physicality required, by default True.

[7]:
from quara.objects.state_ensemble_typical import (
    get_state_ensemble_names,
    generate_state_ensemble_object_from_state_ensemble_name_object_name,
)

print(f"get_state_ensemble_names(): \n{get_state_ensemble_names()}")
get_state_ensemble_names():
['x0', 'x1', 'y0', 'y1', 'z0', 'z1', 'a']

object_name = “state_ensemble”

[8]:
c_sys = generate_composite_system("qubit", 1)
ensemble = generate_state_ensemble_object_from_state_ensemble_name_object_name("z0", "state_ensemble", c_sys=c_sys)
print(ensemble)
Type:
StateEnsemble

States:
states[0]: [0.70710678 0.         0.         0.70710678]
states[1]: [ 0.70710678  0.          0.         -0.70710678]

MultinomialDistribution:
shape = (2,)
ps = [1. 0.]

Download Notebook