How to use the strawberryfields.decompositions.takagi function in StrawberryFields

To help you get started, we’ve selected a few StrawberryFields examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github XanaduAI / strawberryfields / tests / test_decompositions.py View on Github external
def test_takagi_random_symm(self):
        self.logTestName()
        error=np.empty(nsamples)
        for i in range(nsamples):
            X=random_degenerate_symmetric()
            rl, U = dec.takagi(X)
            Xr= U @ np.diag(rl) @ np.transpose(U)
            diff= np.linalg.norm(Xr-X)

            error[i]=diff

        self.assertAlmostEqual(error.mean() , 0)
github XanaduAI / strawberryfields / tests / frontend / test_decompositions.py View on Github external
def test_square_validation(self):
        """Test that the takagi decomposition raises exception if not square"""
        A = np.random.random([4, 5]) + 1j * np.random.random([4, 5])
        with pytest.raises(ValueError, match="matrix must be square"):
            dec.takagi(A)
github BOHRTECHNOLOGY / public_research / Experiments / Yellow_submarine / 2019_01_22_right_parameters / src / yellow_submarine / maxcut_solver_tf.py View on Github external
def build_circuit(self):
        params_counter = 0
        sgates = []
        dgates = []
        kgates = []
        for gate_structure in self.gates_structure:
            if gate_structure[0] is Sgate:
                sgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2]), make_param(**gate_structure[3])]))
            if gate_structure[0] is Dgate:
                dgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2]), make_param(**gate_structure[3])]))
            if gate_structure[0] is Kgate:
                kgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2])]))

        eng, q = sf.Engine(self.n_qumodes)

        rl, U = takagi(self.adj_matrix)
        initial_squeezings = np.tanh(rl)

        with eng:
            for i ,squeeze_value in enumerate(initial_squeezings):
                Sgate(squeeze_value) | i

            Interferometer(U) | q

            for gate in sgates:
                gate.gate(gate.params[0], gate.params[1]) | gate.qumodes

            Interferometer(self.interferometer_matrix) | q

            for gate in dgates:
                gate.gate(gate.params[0], gate.params[1]) | gate.qumodes
github BOHRTECHNOLOGY / public_research / Experiments / Yellow_submarine / 2019_01_17_check_reproducibility / src / yellow_submarine / maxcut_solver_tf.py View on Github external
def build_circuit(self):
        params_counter = 0
        sgates = []
        dgates = []
        kgates = []
        for gate_structure in self.gates_structure:
            if gate_structure[0] is Sgate:
                sgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2]), make_param(**gate_structure[3])]))
            if gate_structure[0] is Dgate:
                dgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2]), make_param(**gate_structure[3])]))
            if gate_structure[0] is Kgate:
                kgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2])]))

        eng, q = sf.Engine(self.n_qumodes)

        rl, U = takagi(self.adj_matrix)
        initial_squeezings = np.arctanh(rl)

        with eng:
            for i ,squeeze_value in enumerate(initial_squeezings):
                Sgate(squeeze_value) | i

            Interferometer(U) | q

            for gate in sgates:
                gate.gate(gate.params[0], gate.params[1]) | gate.qumodes

            Interferometer(self.interferometer_matrix) | q

            for gate in dgates:
                gate.gate(gate.params[0], gate.params[1]) | gate.qumodes
github BOHRTECHNOLOGY / public_research / Experiments / Yellow_submarine / 2019_01_30_ml_approach / src / yellow_submarine / maxcut_solver_ml.py View on Github external
if gate_structure[0] is Sgate:
                current_gate = ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2]), make_param(**gate_structure[3])])
                all_sgates[current_layer].append(current_gate)
            if gate_structure[0] is Dgate:
                current_gate = ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2]), make_param(**gate_structure[3])])
                all_dgates[current_layer].append(current_gate)
            if gate_structure[0] is Kgate:
                current_gate = ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2])])
                all_kgates[current_layer].append(current_gate)
            if gate_structure[0] is Vgate:
                current_gate = ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2])])
                all_vgates[current_layer].append(current_gate)


        eng, q = sf.Engine(self.n_qumodes)
        rl, U = takagi(adj_matrix)
        initial_squeezings = np.arctanh(rl)

        with eng:
            for i ,squeeze_value in enumerate(initial_squeezings):
                Sgate(squeeze_value) | i

            Interferometer(U) | q
            for layer in range(number_of_layers):
                sgates = all_sgates[layer]
                dgates = all_dgates[layer]
                kgates = all_kgates[layer]
                vgates = all_vgates[layer]

                if len(sgates) != 0:
                    Interferometer(self.interferometer_matrix) | q
                    for gate in sgates:
github BOHRTECHNOLOGY / public_research / Experiments / Yellow_submarine / 2019_01_30_ml_approach / src / yellow_submarine / maxcut_solver_tf.py View on Github external
kgates = []
        vgates = []
        for gate_structure in self.gates_structure:
            if gate_structure[0] is Sgate:
                sgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2]), make_param(**gate_structure[3])]))
            if gate_structure[0] is Dgate:
                dgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2]), make_param(**gate_structure[3])]))
            if gate_structure[0] is Kgate:
                kgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2])]))
            if gate_structure[0] is Vgate:
                vgates.append(ParametrizedGate(gate_structure[0], gate_structure[1], [make_param(**gate_structure[2])]))


        eng, q = sf.Engine(self.n_qumodes)

        rl, U = takagi(self.adj_matrix)
        initial_squeezings = np.tanh(rl)

        with eng:
            for i ,squeeze_value in enumerate(initial_squeezings):
                Sgate(squeeze_value) | i

            Interferometer(U) | q

            if len(sgates) != 0:
                Interferometer(self.interferometer_matrix) | q
                for gate in sgates:
                    gate.gate(gate.params[0], gate.params[1]) | gate.qumodes

            if len(dgates) != 0:
                Interferometer(self.interferometer_matrix) | q
                for gate in dgates: