Hello, my name is Alessandro and I’m a master student in physics doing my thesis in quantum computation.
I need to run a boson sampling with few photons (2-4) in a 128 mode Mach-Zehnder Interpherometer. I use pcvl.Circuit.decomposition to decompose a given unitary matrix U (128x128) into a circuit but it doesn’t work (even tried different shape). Anyone has ever met a similar problem and could help me?
Hello,
Can you provide a small code snippet to reproduce your error ? If you use perfect MZI such as
pcvl.Circuit.decomposition(U, BS(theta=pcvl.P('theta'), phi_tr=pcvl.P('phi')), phase_shifter_fn=PS)
,
you should be fine.
If this doesn’t work, you can try to use the Optimizer on a generic interferometer, for example by doing
pcvl.CircuitOptimizer().optimize_rectangle(U)
that uses a different solving process.
I hope this will help you,
Regards
Thank you for replying! The MZI is the perfect one, the same of perceval documentation page. Also the optimizer seems to not working. Anyway here is the snippet:
import perceval as pcvl
import numpy as np
from scipy.stats import unitary_group
from collections import Counter
import time
import random
from perceval.algorithm import Sampler
Parametri per il Boson Sampling
m = 128 # Numero di modi
n = 2 # Numero di fotoni
samples = 50 # Numero di campioni
Generazione di una matrice unitaria casuale di dimensione (modes x modes)
U = pcvl.Matrix.random_unitary(m)
print(U)
Creazione dell’interferometro
mzi = (pcvl.BS() // (0, pcvl.PS(phi=pcvl.Parameter(“φ_a”)))
// pcvl.BS() // (1, pcvl.PS(phi=pcvl.Parameter(“φ_b”))))
pcvl.pdisplay(mzi)
Linear_Circuit = pcvl.Circuit.decomposition(U, mzi,
phase_shifter_fn=pcvl.PS,
shape=pcvl.InterferometerShape.TRIANGLE)
Hello again,
I don’t get any error when running your script. It just takes one or two minutes to run. Can you check that you are using the latest version of perceval (0.12.2)?
If you are using it, or if you still have an error after upgrading, can you copy the error log from the python console?
Regards
Yes, I’m using the latest version. This seems very strange because on 10 trials (all in the same conditions n=2, only different random matrix) 2 times it worked also for me waiting like 10 minutes, in the other cases not. I’ll report you the error (it’s like the decomposition is not giving a circuit but a none):
Traceback (most recent call last):
File “/Users/ale/Documents/tesi/validation.py”, line 59, in
QPU.with_input(input_state)
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/multipledispatch/dispatcher.py”, line 439, in call
return func(self.obj, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/perceval/components/processor.py”, line 181, in with_input
super().with_input(input_state)
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/multipledispatch/dispatcher.py”, line 439, in call
return func(self.obj, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/perceval/components/abstract_processor.py”, line 670, in with_input
self.check_input(input_state)
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/perceval/components/abstract_processor.py”, line 652, in check_input
assert len(input_state) == expected_input_length,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Input length not compatible with circuit (expects 0, got 128)
Indeed, if the decomposition didn’t converge (which it should always do since you are using perfect MZIs as target), the decomposition returns None. You can specify allow_error = True
as argument to the decomposition, but you might end up with circuits relatively far from what you had at the beginning.
Alternatively, if you know where you are going to input your photons, you can use the empty_mode_list
parameter of the CircuitOptimizer.optimize
that will ignore the useless part of the unitary. Beware though that for the CircuitOptimizer
, it returns nothing if it didn’t converge even if allow_error = True
. If you want to use the optimizer, you should give it the result of GenericInterferometer
as template.