sf.lab_dev.wires.Wires¶
- class mrmustard.lab_dev.wires.Wires(modes_out_bra=None, modes_in_bra=None, modes_out_ket=None, modes_in_ket=None)[source]¶
Bases:
objectA class with wire functionality for tensor network applications.
In MrMustard, we represent circuit components as tensors in a tensor network. The wires of these components describe how they connect with the surrounding components. For example, an N-mode pure state has N ket wires on the output side, while a N-mode mixed state has N ket wires and N bra wires on the output side.
Wiresobjects store the information related to the wires of circuit components. Each wire in aWiresobject is specified by a numerical id, which is random and unique. When two differentWiresobject have one or more wires with the same ids, we treat them as connected. Otherwise, we treat them as disconnected.The list of all these ids can be accessed using the
idsproperty.>>> from mrmustard.lab_dev.wires import Wires >>> modes_out_bra=[0, 1] >>> modes_in_bra=[1, 2] >>> modes_out_ket=[0, 3] >>> modes_in_ket=[1, 2, 3] >>> w = Wires(modes_out_bra, modes_in_bra, modes_out_ket, modes_in_ket) >>> # access the modes >>> modes = w.modes >>> assert w.modes == [0, 1, 2, 3] >>> # access the ids >>> ids = w.ids >>> assert len(ids) == 9 >>> # get input/output subsets >>> w_in = w.input >>> assert w_in.modes == [1, 2, 3] >>> # get ket/bra subsets >>> w_in_bra = w_in.bra >>> assert w_in_bra.modes == [1, 2]
The standard order for the list of ids is:
ids for all the output bra wires.
ids for all the input bra wires.
ids for all the output ket wires.
ids for all the input ket wires.
>>> assert w.output.bra.ids == w.ids[:2] >>> assert w.input.bra.ids == w.ids[2:4] >>> assert w.output.ket.ids == w.ids[4:6] >>> assert w.input.ket.ids == w.ids[6:]
To access the index of a su set of wires in standard order (i.e. skipping over wires not belonging to the subset), one can use the
indicesattribute:>>> w = Wires(modes_in_ket = [0,1], modes_out_ket = [0,1]) >>> assert w.indices == [0,1,2,3] >>> assert w.input.indices == [2,3]
Note that subsets return new
Wiresobjects with the same ids as the original object.- Parameters:
modes_out_bra (
Optional[Iterable[int]]) – The output modes on the bra side.modes_in_bra (
Optional[Iterable[int]]) – The input modes on the bra side.modes_out_ket (
Optional[Iterable[int]]) – The output modes on the ket side.modes_in_ket (
Optional[Iterable[int]]) – The input modes on the ket side.
Note that the order of the modes passed to initialize the object doesn’t matter, as they get sorted at init time.
Attributes
The adjoint of this wires object, obtained by swapping ket and bra wires.
A view of this
Wiresobject without ket wires.The dual of this wires object, obtained by swapping input and output wires.
The id_array of the available wires in a two-dimensional array, where line
jcontains the ids (in the standard order) for modej.The list of ids of the available wires in the standard order.
The array of indices of this
Wiresin the standard order.A view of this
Wiresobject without output wires.A view of this
Wiresobject without bra wires.The list of modes of the populated wires.
A view of this
Wiresobject without input wires.- adjoint¶
The adjoint of this wires object, obtained by swapping ket and bra wires.
- bra¶
A view of this
Wiresobject without ket wires.
- dual¶
The dual of this wires object, obtained by swapping input and output wires.
- id_array¶
The id_array of the available wires in a two-dimensional array, where line
jcontains the ids (in the standard order) for modej.
- ids¶
The list of ids of the available wires in the standard order.
- indices¶
The array of indices of this
Wiresin the standard order. The array of indices of thisWiresin the standard order. When a subset is selected, it skips the indices of wires that do not belong to the subset.>>> w = Wires(modes_in_ket = [0,1], modes_out_ket = [0,1]) >>> assert w.indices == [0,1,2,3] >>> assert w.input.indices == [2,3]
- input¶
A view of this
Wiresobject without output wires.
- ket¶
A view of this
Wiresobject without bra wires.
- modes¶
The list of modes of the populated wires.
- output¶
A view of this
Wiresobject without input wires.
Methods