qml.bose.BoseWord¶
- class BoseWord(operator)[source]¶
Bases:
dict
Dictionary used to represent a Bose word, a product of bosonic creation and annihilation operators, that can be constructed from a standard dictionary.
The keys of the dictionary are tuples of two integers. The first integer represents the position of the creation/annihilation operator in the Bose word and the second integer represents the mode it acts on. The values of the dictionary are one of
'+'
or'-'
symbols that denote creation and annihilation operators, respectively. The operator \(b^{\dagger}_0 b_1\) can then be constructed as>>> w = qml.BoseWord({(0, 0) : '+', (1, 1) : '-'}) >>> print(w) b⁺(0) b(1)
Attributes
Methods
adjoint
()Return the adjoint of BoseWord.
clear
()copy
()fromkeys
([value])Create a new dictionary with keys from iterable and values set to value.
get
(key[, default])Return the value for key if key is in the dictionary, else default.
items
()Returns the dictionary items in sorted order.
keys
()Convert a BoseWord to its normal-ordered form.
pop
(k[,d])If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem
()Remove and return a (key, value) pair as a 2-tuple.
setdefault
(key[, default])Insert key with a value of default if key is not in the dictionary.
shift_operator
(initial_position, final_position)Shifts an operator in the BoseWord from
initial_position
tofinal_position
by applying the bosonic commutation relations.Return a compact string representation of a BoseWord.
update
(item)Restrict updating BoseWord after instantiation.
values
()- clear() None. Remove all items from D. ¶
- copy() a shallow copy of D ¶
- fromkeys(value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- keys() a set-like object providing a view on D's keys ¶
- normal_order()[source]¶
Convert a BoseWord to its normal-ordered form.
>>> bw = qml.BoseWord({(0, 0): "-", (1, 0): "-", (2, 0): "+", (3, 0): "+"}) >>> print(bw.normal_order()) 4.0 * b⁺(0) b(0) + 2.0 * I + 1.0 * b⁺(0) b⁺(0) b(0) b(0)
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()¶
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- shift_operator(initial_position, final_position)[source]¶
Shifts an operator in the BoseWord from
initial_position
tofinal_position
by applying the bosonic commutation relations.- Parameters
initial_position (int) – the position of the operator to be shifted
final_position (int) – the desired position of the operator
- Returns
The
BoseSentence
obtained after applying the commutator relations.- Return type
- Raises
TypeError – if
initial_position
orfinal_position
is not an integerValueError – if
initial_position
orfinal_position
are outside the range[0, len(BoseWord) - 1]
wherelen(BoseWord)
is the number of operators in the BoseWord.
- to_string()[source]¶
Return a compact string representation of a BoseWord. Each operator in the word is represented by the number of the wire it operates on, and a + or - to indicate either a creation or annihilation operator.
>>> w = qml.BoseWord({(0, 0) : '+', (1, 1) : '-'}) >>> w.to_string() 'b⁺(0) b(1)'
- values() an object providing a view on D's values ¶