API
Quantum Optical Circuit
- class qoptkit.qocircuit(nch, dummy=False)
A quantum circuit consists in a set of interconnected quantum optical elements.
- Nch (int)
Number of channels
- Dummy(automatic(bool))
If True it creates a dummy empty class. (Option used internally by the library).
barrier
()Adds a graphical separator between two circuit sections
bs
(ch1, ch2, theta, phi)Adds a beamsplitter to the quantum circuit attached to channels ch1 and ch2.
gate
(chlist, qoc, text)Adds a gate using other circuit as the gate definition.
num_ch
()Returns the total number of channels of the circuit.
ph
(ch, phi)Adds a phase shifter to the circuit in channel ch.
show
([depth, sizexy, font, rows])Plots the quantum circuit.
swp
(ch1, ch2)Adds a swap gate between two channels
num_ch
- qocircuit.num_ch()
Returns the total number of channels of the circuit.
- Return(int)
Number of channels of the circuit.
bs
- qocircuit.bs(ch1, ch2, theta, phi)
Adds a beamsplitter to the quantum circuit attached to channels ch1 and ch2.
- Ch1 (int)
Beamsplitter input channel 1.
- Ch2 (int)
Beamsplitter input channel 2.
ph
- qocircuit.ph(ch, phi)
Adds a phase shifter to the circuit in channel ch.
- Ch (int)
Phase shifter input channel.
- Phi (float)
Angle phi in degrees.
swp
- qocircuit.swp(ch1, ch2)
Adds a swap gate between two channels
- Ch1 (int)
Channel 1.
- Ch2 (int)
Channel 2.
gate
- qocircuit.gate(chlist, qoc, text)
Adds a gate using other circuit as the gate definition.
- Chlist (list[int])
List of channels to which the new gate is attached
- Qoc (qocircuit)
Circuit defining the gate
barrier
- qocircuit.barrier()
Adds a graphical separator between two circuit sections
show
- qocircuit.show(depth=10, sizexy=100, font=18, rows=1)
Plots the quantum circuit.
- Depth (optional[int])
Number of plot layers. The longer the circuit the more needed.
- Sizexy(optional[int])
How many pixels by layer. Controls the size of the plot.
- Font (optional[int])
Font size of the labels.
- Rows(int)
Numbers of printing lines to be used by the plotter.
State
- class qoptkit.state(level, st=[], nph=- 1, maxket=50, dummy=False)
Quantum photonic state definition. A quantum state is a sum of kets multiplied by amplitudes.
- Level (int)
Number of channels to describe the state.
- St(optional(list[[complex,list[int]]])
List of kets described as a 2.tuple of a comlpex number representing the amplitude and a list of occupations by channel.
- Nph(optional(int))
Maximum number of photons of the state.
- Maxket(optional(int))
Maximum number of kets. (Internal memory).
- Dummy(automatic(bool))
If True it creates a dummy empty class. (Option used internally by the library).
add_ket
(ampl, vec)Adds a new ket to the state using a vector with the level occupation.
braket
(state)Performs the bra-ket operation <bra|state> using the complex conjugate of this state as bra.
campl
(index)Returns the amplitude of probability of the required ket
encode
(qmap, qoc)Encode a state into a qubit encoding.
decode
(qmap, ancilla, qoc)Decode a state from a qubit encoding into photon encoding.
ket_list
()Return state as a list of 2-tuples of amplitudes and occupations.
Normalizes the state.
post_selection
(cond)Post-selection over states by the condition defined by the list cond.
Prints a state.
nkets
()Returns the number of kets stored.
num_ch
()Returns the number of channels.
show
([pmax, sizex, sizey, dpi, angle, font])Plots the outcomes in a bar diagram.
tag
(index)Returns the tag of the ket required.
add_ket
- state.add_ket(ampl, vec)
Adds a new ket to the state using a vector with the level occupation.
- Ampl(complex)
Amplitude of the new ket.
- Vec(list[int])
List with the occupation of each channel in the new ket.
braket
- state.braket(state)
Performs the bra-ket operation <bra|state> using the complex conjugate of this state as bra.
- State(state)
State in the right hand side of the braket operation.
- Return (complex)
The complex number result of the projection.
normalize
- state.normalize()
Normalizes the state.
post_selection
- state.post_selection(cond)
Post-selection over states by the condition defined by the list cond.
- Cond(list[int])
Description of the post-selection condition a list of occupations by channel. Channels with negative values of the occupation are not post-selected.
- Return (state)
Post-selected state.
encode
- state.encode(qmap, qoc)
Encode a state into a qubit encoding. Those kets that can not be encoded are dismissed and the result is normalized.
Warning! t is responsibility of the library user to make sure that no ket repetitions arise after encoding.
- Qmap(list[][])
nx2 matrix with the qubit definitions. Each row has two entries specifying the channels that define the qubit.
- Qoc(qocircuit)
Circuit to which the state is related.
- Return output(state)
An encoded state.
decode
- state.decode(qmap, ancilla, qoc)
Decode a state from a qubit encoding into photon encoding. Note that we need to define the values of the extra ancilla channels that are not included into the qubit encoding but they are needed to the circuit to work in the intended way
- Qmap(list[][])
nx2 matrix with the qubit definitions. Each row has two entries specifying the channels that define the qubit.
- Ancilla(list[int])
List with the values of the ancilla channels (from smaller to large channel number).
- Qoc(qocircuit)
Circuit which the state is related.
- Return output(state)
A decoded state.
prnt_state
- state.prnt_state()
Prints a state.
nkets
- state.nkets()
Returns the number of kets stored.
- Return (int)
Number of kets.
num_ch
- state.num_ch()
Returns the number of channels.
- Return (int)
Number of channels.
campl
- state.campl(index)
Returns the amplitude of probability of the required ket
- Index (int)
Index of the ket.
- Return (int)
Amplitude of probability of the referred ket.
tag
- state.tag(index)
Returns the tag of the ket required.
- Index (int)
Index of a ket.
- Return (string)
Occupation in string format.
ket_list
- state.ket_list()
Return state as a list of 2-tuples of amplitudes and occupations.
- Return (list[[complex,[int]])
List of 2-tuples of a ket amplitude and a list of occupations by channel.
show
- state.show(pmax=- 1.0, sizex=8, sizey=5, dpi=100, angle=70, font=14)
Plots the outcomes in a bar diagram.
- Pmax(optional[float])
Maximum value of the probabiilty.
- Sizex(optional[float])
Size of the plot in the x direction in inches.
- Sizey(optional[float])
Size of the plot in the y direction in inches.
- Dpi(optional[float])
Density of points by inch.
- Angle(optional[float])
Angle of the horizontal axis labels.
- Font(optional[fint])
Size of the font of the horizontal axis labels.
Quantum Circuit Simulator
- class qoptkit.simulator(mem=1000)
Simulator that can be used to calculate the output state of a circuit given an input state.
- Mem(optional([int])
Reserved memory for the output expressed as a maximum number of kets. (Internal memory)
run
(istate, qoc)Calculates an output state as a function of an input initial state for a given quantum circuit.
run
- simulator.run(istate, qoc)
Calculates an output state as a function of an input initial state for a given quantum circuit.
- Istate(state)
Initial state.
- Qoc(qocircuit)
Input quantum circuit.
- Return(state)
Output state.
Compiler
- class qoptkit.compiler(mem=1000)
Compiler between optical circuits defined in qoptkit and logical circuits defined in QISKIT.
- Mem(optional([int])
Number of kets in the internal memory.
assemble
(in_cond, out_cond, occ, psel, ...)Creates a transpiled circuit geiven an optical circuit
return_matrix
(in_cond, out_cond, occ, psel, qoc)Returns the matrix that relates the qubit encoded input and output states to export to QISKIT.
transpile
(qc)Transpile a logical circuit into a quantum circuit using a substitution method.
assemble
- compiler.assemble(in_cond, out_cond, occ, psel, basis, qoc, measure='qoptkit')
Creates a transpiled circuit geiven an optical circuit
- In_cond(list[][])
nx2 matrix with the input qubit definitions.
- Out_cond(list[][])
nx2 matrix with the output qubit definitions.
- Occ(list[int])
List of default occupation by input channels in case the channels are not defined as part of in_cond.
- Psel(list[int])
Post-selection condition of the circuit as a list of occupations by channel. Negative occupation means no post-selection for that channel.
- Basis(list)
List of the allowed gates for transpilation.
- Qoc(qocircuit)
Circuit to be assembled
- Measure(optional[string])
We measure following “qoptkit” or “qiskit” protocols. In qoptkit the smaller qubit (qubit 0) appear at the left when defining the outcomes while in QISKIT is the other way around.
- Return circ(QuantumCircuit)
Returns the full assembled circuit.
return_matrix
- compiler.return_matrix(in_cond, out_cond, occ, psel, qoc)
Returns the matrix that relates the qubit encoded input and output states to export to QISKIT.
- In_cond(list[][])
nx2 matrix with the input qubit definitions.
- Out_cond(list[][])
nx2 matrix with the output qubit definitions.
- Occ(list[int])
List of default occupation by input channels in case the channels are not defined as part of in_cond.
- Psel(list[int])
Post-selection condition of the circuit as a list of occupations by channel. Negative occupation means no post-selection for that channel.
- Qoc(qocircuit)
Circuit to obtain the logic matrix
- Return mtx(list[][])
Returns a square circuit matrix containing the matrix in qubit encoding that represents the logic of the optical circuit.
transpile
- compiler.transpile(qc)
Transpile a logical circuit into a quantum circuit using a substitution method.
- Qc(QuantumCircuit)
Circuit defined in QISKIT to be transpiled.
- Return (qocircuit, list[int][int] , list[int], QuantumCircuit)
Returns in this order:
* An optical circuit fullfilling the same functionality that the logical circuit.
* A matrix with the qubit-channel encoding.
* A list of the ancilla channels.
* A list with the post-selection condition.
* A transpiled QuantumCircuit with rotations and controled phase flips as gates.
Configuration methods
cfg_qoptkit
- qoptkit.cfg_qoptkit(nph)
It defines the default maximum number of photons to be used by qoptkit.
- Nph (int)
Maximum number of photons used by qoptkit.