def test_is_unitary_with_channel(self, prog):
     """test that the is_unitary function returns False if channels are present"""
     with prog.context as q:
         Sgate(0.4) | q[0]
         LossChannel(0.4) | q[0]
         BSgate(0.4) | q
     assert not utils.is_unitary(prog)
 def test_is_channel_no_measurement(self, prog):
     """test that the is_channel function returns True if no measurements are present"""
     assert utils.is_channel(prog)
     with prog.context as q:
         Sgate(0.4) | q[0]
         LossChannel(0.4) | q[0]
         BSgate(0.4) | q
     assert utils.is_channel(prog)
Beispiel #3
0
    def test_is_unitary_with_channel(self):
        """test that the is_unitary function returns False if channels are present"""
        eng, q = sf.Engine(2)

        with eng:
            Sgate(0.4) | q[0]
            LossChannel(0.4) | q[0]
            BSgate(0.4) | q

        assert not utils.is_unitary(eng)
Beispiel #4
0
    def test_is_channel_no_measurement(self):
        """test that the is_channel function returns True if no measurements are present"""
        eng, q = sf.Engine(2)

        assert utils.is_channel(eng)

        with eng:
            Sgate(0.4) | q[0]
            BSgate(0.4) | q

        assert utils.is_channel(eng)

        with eng:
            Sgate(0.4) | q[0]
            LossChannel(0.4) | q[0]
            BSgate(0.4) | q

        assert utils.is_channel(eng)
    etas_loop = device.certificate["loop_efficiencies"]

    # a list with the relative efficiencies of the 16 detector channels
    etas_ch_rel = device.certificate["relative_channel_efficiencies"]

    # the detector-channel efficiencies are cyclic, so mode ``i`` sees the same
    # efficiency as mode ``i+1``
    prog_length = len(gate_args_list[0])
    reps = int(np.ceil(prog_length / 16))
    etas_ch_rel = np.tile(etas_ch_rel, reps)[:prog_length]

    # create a Strawberry Fields program for a local simulation
    prog_sim = sf.TDMProgram(N)
    with prog_sim.context(*gate_args_list, etas_ch_rel) as (p, q):
        Sgate(p[0]) | q[n[0]]
        LossChannel(eta_glob) | q[n[0]]
        for i in range(len(delays)):
            Rgate(p[2 * i + 1]) | q[n[i]]
            BSgate(p[2 * i + 2], np.pi / 2) | (q[n[i + 1]], q[n[i]])
            LossChannel(etas_loop[i]) | q[n[i]]
        LossChannel(p[7]) | q[0]
        MeasureFock() | q[0]
    prog_sim.space_unroll()

    # create Gaussian engine and submit program to it
    eng_sim = sf.Engine(backend="gaussian")
    results_sim = eng_sim.run(prog_sim, shots=None, crop=True)

    # obtain quadrature covariance matrix
    cov = results_sim.state.cov()