qnet.algebra.toolbox.circuit_manipulation module

Summary

Functions:

connect Connect a list of components according to a list of connections.

__all__: connect

Reference

qnet.algebra.toolbox.circuit_manipulation.connect(components, connections, force_SLH=False, expand_simplify=True)[source]

Connect a list of components according to a list of connections.

Parameters:
  • components (list) – List of Circuit instances
  • connections (list) – List of pairs ((c1, port1), (c2, port2)) where c1 and c2 are elements of components (or the index of the element in components), and port1 and port2 are the indices (or port names) of the ports of the two components that should be connected
  • force_SLH (bool) – If True, convert the result to an SLH object
  • expand_simplify (bool) – If the result is an SLH object, expand and simplify the circuit after each feedback connection is added

Example

>>> A = CircuitSymbol('A', cdim=2)
>>> B = CircuitSymbol('B', cdim=2)
>>> BS = Beamsplitter()
>>> circuit = connect(
...     components=[A, B, BS],
...     connections=[
...         ((A, 0),  (BS, 'in')),
...         ((BS, 'tr'), (B, 0)),
...         ((A, 1), (B, 1))])
>>> print(unicode(circuit).replace('cid(1)', '1'))
(B ⊞ 1) ◁ Perm(0, 2, 1) ◁ (BS(π/4) ⊞ 1) ◁ Perm(0, 2, 1) ◁ (A ⊞ 1)

The above example corresponds to the circuit diagram:

 ┌─┐    ┌───────┐    ┌─┐
>┤ ├───>┤       ├───>┤ ├
 │A│    │BS(π/4)│    │B│
>┤ ├┐┌─>┤       ├┐┌─>┤ ├
 └─┘└│  └───────┘└│  └─┘
     │┐           │┐
─────┘└───────────┘└────
Raises:ValueError – if connections includes any invalid entries

Note

The list of components may contain duplicate entries, but in this case you must use a positional index in connections to refer to any duplicate component. Alternatively, use unique components by defining different labels.