Skip to main content

Qbit

An object representing a product state of qubits.

This class represents a product state of qubits together with its associated multiplicative coefficient. Each qubit (0\vert 0 \rangle or 1\vert 1 \rangle) corresponds respectively to the +1+1 and 1-1 eigenstates of the Pauli ZZ operator. In other words, Z0=0,Z1=1.Z \vert 0 \rangle = \vert 0 \rangle, \quad Z \vert 1 \rangle = -\vert 1 \rangle. The number of qubits in the product state corresponds to the number of sites on which it has support.

Factories

Qbit(integer num_sites) -> Qbit

Constructs a qubit product state of size num_sites with every qubit set to 00.

Parameters

  • num_sites: The number of qubits in the product state in a one to one correspondence with the sites.

Example

Qbit(4) // Returns (1 + 0i)|0000>

Qbit(const string bitstring) -> Qbit

Constructs a qubit product state from a string of consecutive characters "00" and "11".

Parameters

  • bitstring: A string representing the states of the qubits in the product state.

Example

Qbit("00110") // Returns (1 + 0i)|00110>

Qbit(integer num_sites, complex coefficient) -> Qbit

Constructs a qubit product state of the specified size with every qubit set to 00 with a specified complex multiplicative coefficient.

Parameters

  • num_sites: The number of qubits in the product state in a one to one correspondence with the sites.
  • coefficient: The coefficient that multiplies the qubit product state.

Example

Qbit(4, 2.0 + 5.0i) // Returns (2 + 5i)|0000>

Qbit(integer num_sites, bool coefficient) -> Qbit

Constructs a qubit product state of the specified size with every qubit set to 00 with a specified bool (converted to complex) multiplicative coefficient.

Parameters

  • num_sites: The number of qubits in the product state in a one to one correspondence with the sites.
  • coefficient: The coefficient that multiplies the qubit product state.

Example

Qbit(4, true) // Returns (1 + 0i)|0000>

Qbit(const string bitstring, real coefficient) -> Qbit

Constructs a qubit product state from a string of "00" and "11" with a specified real (converted to complex) multiplicative coefficient.

Parameters

  • bitstring: A string representing the states of the qubits in the product state.
  • coefficient: The coefficient that multiplies the qubit product state.

Example

Qbit("00110", 2.0) // Returns (2 + 0i)|00110>

Qbit(const string bitstring, bool coefficient) -> Qbit

Constructs a qubit product state from a string of "00" and "11" with a specified bool (converted to complex) multiplicative coefficient.

Parameters

  • bitstring: A string representing the states of the qubits in the product state.
  • coefficient: The coefficient that multiplies the qubit product state.

Example

Qbit("00110", true) // Returns (1 + 0i)|00110>

Qbit(const string bitstring, complex coefficient) -> Qbit

Constructs a qubit product state from a string of "00" and "11" with a specified complex multiplicative coefficient.

Parameters

  • bitstring: A string representing the states of the qubits in the product state.
  • coefficient: The coefficient that multiplies the qubit product state.

Example

Qbit("00110", 2.0 + 5.0i) // Returns (2 + 5i)|00110>

Qbit(integer num_sites, real coefficient) -> Qbit

Constructs a qubit product state of the specified size with every qubit set to 00 with a specified real (converted to complex) multiplicative coefficient.

Parameters

  • num_sites: The number of qubits in the product state in a one to one correspondence with the sites.
  • coefficient: The coefficient that multiplies the qubit product state.

Example

Qbit(4, 2.0) // Returns (2 + 0i)|0000>

Qbit(const string bitstring, integer coefficient) -> Qbit

Constructs a qubit product state from a string of "00" and "11" with a specified integer (converted to complex) multiplicative coefficient.

Parameters

  • bitstring: A string representing the states of the qubits in the product state.
  • coefficient: The coefficient that multiplies the qubit product state.

Example

Qbit("00110", 3) // Returns (3 + 0i)|00110>

Qbit(integer num_sites, integer coefficient) -> Qbit

Constructs a qubit product state of the specified size with every qubit set to 00 with a specified integer (converted to complex) multiplicative coefficient.

Parameters

  • num_sites: The number of qubits in the product state in a one to one correspondence with the sites.
  • coefficient: The coefficient that multiplies the qubit product state.

Example

Qbit(4, 3) // Returns (3 + 0i)|0000>

Symbols

NameDescription
*=Multiplies the Qbit coefficient by a complex value in place.
=Assignment operator for Qbit objects.

Members

NameDescription
countReturns the sum of the qubit states on a subset of indices (interpreted as integers) in the product state.
flipThis method modifies the Qbit object in place by flipping the state of the qubits at the specified sites.
flippedReturns a copy of the product state with the qubits at the specified sites flipped.
insertInserts a qubit set to the specified value at the specified site.
insertedReturns a copy of the product state with a qubit in the 00 state inserted to the left of the qubit at the specified site.
periodReturns the number of times the qubits have to be circularly shifted to the right by one site before the obtained product state is equal to the starting product state.
permutePermutes in place the qubits of the product state according to the specified permutation vector.
permutedReturns a copy of the product state with its qubits permuted according to the specified permutation vector.
reflectReverses the product state (reversed end-to-end) in place.
reflectedReturns a copy of the reflected (reversed end-to-end) product state.
set_representationSets the integer representation of the Qbit.
splitSplits the Qbit into two parts, returning a list containing the resulting left and right qubit.
swapThis methods swaps the qubits of the product state at the specified sites in place.
swappedReturns a copy of the Qbit object with two specified qubits swapped.
translateCircularly shifts in place the qubits of the product state by 11 site to the right.
translatedReturns a copy of the product state with its qubits shifted by 11 site to the right a number of times equal to the provided integer.