toqito.states.ghz
- toqito.states.ghz(dim, num_qubits, coeff=None)[source]
Generate a (generalized) GHZ state [GHZ07].
Returns a
num_qubits-partite GHZ state acting ondimlocal dimensions, described in [GHZ07]. For example,ghz(2, 3)returns the standard 3-qubit GHZ state on qubits. The output of this function is sparse.For a system of
num_qubitsqubits (i.e.,dim = 2), the GHZ state can be written as\[|GHZ \rangle = \frac{1}{\sqrt{n}} \left(|0\rangle^{\otimes n} + |1 \rangle^{\otimes n} \right)).\]Examples
When
dim = 2, andnum_qubits = 3this produces the standard GHZ state\[\frac{1}{\sqrt{2}} \left( |000 \rangle + |111 \rangle \right).\]Using
toqito, we can see that this yields the proper state.>>> from toqito.states import ghz >>> ghz(2, 3).toarray() [[0.70710678], [0. ], [0. ], [0. ], [0. ], [0. ], [0. ], [0.70710678]]
As this function covers the generalized GHZ state, we can consider higher dimensions. For instance here is the GHZ state in \(\mathbb{C}^{4^{\otimes 7}}\) as
\[\frac{1}{\sqrt{30}} \left(|0000000 \rangle + 2|1111111 \rangle + 3|2222222 \rangle + 4|3333333\rangle \right).\]Using
toqito, we can see this generates the appropriate generalized GHZ state.>>> from toqito.states import ghz >>> ghz(4, 7, np.array([1, 2, 3, 4]) / np.sqrt(30)).toarray() [[0.18257419], [0. ], [0. ], ..., [0. ], [0. ], [0.73029674]])
References
- Raises:
ValueError – Number of qubits is not a positive integer.
- Parameters:
dim – The local dimension.
num_qubits – The number of parties (qubits/qudits)
coeff – (default [1, 1, …, 1])/sqrt(dim): a 1-by-dim vector of coefficients.
- Returns:
Numpy vector array as GHZ state.