quimb.gen.states

Functions for generating quantum states.

Functions

basis_vec(i, dim[, ownership])

Constructs a unit vector ket.

bell_state(s, **kwargs)

One of the four bell-states.

bloch_state(ax, ay, az[, purified])

Construct qubit density operator from bloch vector.

computational_state(binary, **kwargs)

Generate the qubit computational state with binary.

down(**kwargs)

Returns down-state, aka.

ghz_state(n, **kwargs)

Construct GHZ state of n spins, i.e. equal superposition of all up and down.

graph_state_1d(n[, cyclic, sparse])

Graph State on a line.

levi_civita(perm)

Compute the generalised levi-civita coefficient for a permutation.

minus(**kwargs)

Returns minus-state, aka.

neel_state(n[, down_first])

Construct Neel state for n spins, i.e. alternating up/down.

perm_state(ps)

Construct the anti-symmetric state which is the +- sum of all tensored permutations of states ps.

plus(**kwargs)

Returns plus-state, aka.

singlet(**kwargs)

Alias for the ‘psi-‘ bell-state.

singlet_pairs(n, **kwargs)

Construct fully dimerised spin chain.

thermal_state(ham, beta[, precomp_func])

Generate a thermal state of a Hamiltonian.

up(**kwargs)

Returns up-state, aka.

w_state(n, **kwargs)

Construct W-state: equal superposition of all single spin up states.

werner_state(p, **kwargs)

Construct Werner State, i.e. fractional mix of identity with singlet.

xminus(**kwargs)

Returns minus-state, aka.

xplus(**kwargs)

Returns plus-state, aka.

yminus(**kwargs)

Returns yplus-state, aka.

yplus(**kwargs)

Returns yplus-state, aka.

zminus(**kwargs)

Returns down-state, aka.

zplus(**kwargs)

Returns up-state, aka.

quimb.gen.states.basis_vec(i, dim, ownership=None, **kwargs)[source]

Constructs a unit vector ket.

Parameters
  • i (int) – Which index should the single non-zero, unit entry.

  • dim (int) – Total size of hilbert space.

  • sparse (bool, optional) – Return vector as sparse matrix.

  • kwargs – Supplied to qu.

  • Returns

  • --------

  • vector – The basis vector.

quimb.gen.states.bell_state(s, **kwargs)[source]

One of the four bell-states.

If n = 2**-0.5, they are:

  1. 'psi-' : n * ( |01> - |10> )

  2. 'psi+' : n * ( |01> + |10> )

  3. 'phi-' : n * ( |00> - |11> )

  4. 'phi+' : n * ( |00> + |11> )

They can be enumerated in this order.

Parameters
  • s (str or int) – String of number of state corresponding to above.

  • kwargs – Supplied to qu called on state.

Returns

p – The bell-state s.

Return type

immutable vector

quimb.gen.states.bloch_state(ax, ay, az, purified=False, **kwargs)[source]

Construct qubit density operator from bloch vector.

Parameters
  • ax (float) – X component of bloch vector.

  • ay (float) – Y component of bloch vector.

  • az (float) – Z component of bloch vector.

  • purified – Whether to map vector to surface of bloch sphere.

Returns

Density operator of qubit ‘pointing’ in (ax, ay, az) direction.

Return type

Matrix

quimb.gen.states.computational_state(binary, **kwargs)[source]

Generate the qubit computational state with binary.

Parameters

binary (sequence of 0s and 1s) – The binary of the computation state.

Examples

>>> computational_state('101'):
qarray([[0.+0.j],
        [0.+0.j],
        [0.+0.j],
        [0.+0.j],
        [0.+0.j],
        [1.+0.j],
        [0.+0.j],
        [0.+0.j]])
>>> qu.computational_state([0, 1], qtype='dop')
qarray([[0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j]])

See also

MPS_computational_state(), basic_vec()

quimb.gen.states.down(**kwargs)[source]

Returns down-state, aka. |1>, -Z eigenstate.

quimb.gen.states.ghz_state(n, **kwargs)[source]

Construct GHZ state of n spins, i.e. equal superposition of all up and down.

Parameters
  • n (int) – Number of spins.

  • kwargs – Supplied to qu called on state.

Returns

Return type

vector

quimb.gen.states.graph_state_1d(n, cyclic=True, sparse=False)[source]

Graph State on a line.

Parameters
  • n (int) – The number of spins.

  • cyclic (bool, optional) – Whether to use cyclic boundary conditions for the graph.

  • sparse (bool, optional) – Whether to return a sparse state.

Returns

The 1d-graph state.

Return type

vector

quimb.gen.states.levi_civita(perm)[source]

Compute the generalised levi-civita coefficient for a permutation.

Parameters

perm (sequence of int) – The permutation, a re-arrangement of range(n).

Returns

Either -1, 0 or 1.

Return type

int

quimb.gen.states.minus(**kwargs)[source]

Returns minus-state, aka. |->, -X eigenstate.

quimb.gen.states.neel_state(n, down_first=False, **kwargs)[source]

Construct Neel state for n spins, i.e. alternating up/down.

Parameters
  • n (int) – Number of spins.

  • down_first (bool, optional) – Whether to start with ‘1’ or ‘0’ first.

  • kwargs – Supplied to qu called on state.

See also

computational_state(), MPS_neel_state()

quimb.gen.states.perm_state(ps)[source]

Construct the anti-symmetric state which is the +- sum of all tensored permutations of states ps.

Parameters

ps (sequence of states) – The states to combine.

Returns

The permutation state, dimension same as kron(*ps).

Return type

vector or operator

Examples

A singlet is the perm_state of up and down.

>>> states = [up(), down()]
>>> pstate = perm_state(states)
>>> expec(pstate, singlet())
1.0
quimb.gen.states.plus(**kwargs)[source]

Returns plus-state, aka. |+>, +X eigenstate.

quimb.gen.states.singlet(**kwargs)[source]

Alias for the ‘psi-‘ bell-state.

quimb.gen.states.singlet_pairs(n, **kwargs)[source]

Construct fully dimerised spin chain.

I.e. bell_state('psi-') & bell_state('psi-') & ...

Parameters
  • n (int) – Number of spins.

  • kwargs – Supplied to qu called on state.

Returns

Return type

vector

quimb.gen.states.thermal_state(ham, beta, precomp_func=False)[source]

Generate a thermal state of a Hamiltonian.

Parameters
  • ham (operator or (1d-array, 2d-array)) – Hamiltonian, either full or tuple of (evals, evecs).

  • beta (float) – Inverse temperature of state.

  • precomp_func (bool, optional) – If True, return a function that takes beta only and is closed over the solved hamiltonian.

Returns

Density operator of thermal state, or function to generate such given a temperature.

Return type

operator or callable

quimb.gen.states.up(**kwargs)[source]

Returns up-state, aka. |0>, +Z eigenstate.

quimb.gen.states.w_state(n, **kwargs)[source]

Construct W-state: equal superposition of all single spin up states.

Parameters
  • n (int) – Number of spins.

  • kwargs – Supplied to qu called on state.

Returns

Return type

vector

quimb.gen.states.werner_state(p, **kwargs)[source]

Construct Werner State, i.e. fractional mix of identity with singlet.

Parameters
  • p (float) – Singlet Fraction.

  • kwargs – Supplied to qu() called on state.

Returns

Return type

qarray

quimb.gen.states.xminus(**kwargs)

Returns minus-state, aka. |->, -X eigenstate.

quimb.gen.states.xplus(**kwargs)

Returns plus-state, aka. |+>, +X eigenstate.

quimb.gen.states.yminus(**kwargs)[source]

Returns yplus-state, aka. |y->, -Y eigenstate.

quimb.gen.states.yplus(**kwargs)[source]

Returns yplus-state, aka. |y+>, +Y eigenstate.

quimb.gen.states.zminus(**kwargs)

Returns down-state, aka. |1>, -Z eigenstate.

quimb.gen.states.zplus(**kwargs)

Returns up-state, aka. |0>, +Z eigenstate.