SOQCS Example 1: Introduction to using SOQCS

Elementary example of SOQCS for a simple circuit with only one beamsplitter.

Structure:

- Create a circuit.
- Build the circuit.
- Create a simulator to run it.
- Run the simulation.
- Print the output probabilities.

Import and configure library

[1]:
import soqcs

Managing photons

Create and build a circuit, including populating the channels with photons.

[2]:
# Create circuit
example = soqcs.qodev(2,2);

# Build circuit
example.empty_channel(0)
example.add_photons(2,1)
example.separator()
example.beamsplitter(0,1,45.0,0.0)
example.separator()
example.detector(0)
example.detector(1)

Plot the circuit.

[3]:
example.show(depth=7,sizexy=70)
_images/live1_8_0.png

Create a simulator and run the simulation.

[4]:
simulator=soqcs.simulator()
outcome=simulator.run(example)

Print the outcome.

[5]:
outcome.prnt_bins()
 0 :  | 2, 0 >: 0.25
 1 :  | 1, 1 >: 0.5
 2 :  | 0, 2 >: 0.25

Plot the outcome.

[6]:
outcome.show(dpi=70)
_images/live1_14_0.png

Managing states

We build the circuit again but in this case we use the most basic qocircuit class.

[7]:
# Create a circuit
example = soqcs.qocircuit(2);

# Build circuit
example.beamsplitter(0,1,45.0,0.0)
example.detector(0)
example.detector(1)

In contrast to the previous class qodev, photons can not be declared directly in qocircuit but the initial state has to be initialized separately.

[11]:
# Create input state
inputst = soqcs.state(example.num_levels(),10)

# Initialize input state
term=[[0,1], # Channels
      [0,2]] # Occupations
inputst.add_term(1.0,term,example)

After simulation the output state is obtained. Note that the command to run the simulation is different than in the previous case.

[9]:
# Create simulator
simulator=soqcs.simulator()

# Run the simulation
outputst=simulator.run_st(inputst,example)

Print the output state.

[12]:
outputst.prnt_state()
(0.5,0) *  | 2, 0 > + (-0.7071,0) *  | 1, 1 > + (0.5,0) *  | 0, 2 >

THIS CODE IS PART OF SOQCS

Copyright: Copyright © 2023 National University of Ireland Maynooth, Maynooth University. All rights reserved. The contents and use of this document and the related code are subject to the licence terms detailed in LICENCE.txt