Пример #1
0
    def test_compile_with_create_program(self):
        """Test that a program can be compiled correctly using the Borealis compiler when using
        ``Device.create_program``"""
        params = borealis_gbs(borealis_device, return_list=True)
        assert isinstance(params, list)

        # add loop-phases
        params.extend([[4.0], [2.0], [1.0]])
        names = [
            "s",
            "r0",
            "bs0",
            "r1",
            "bs1",
            "r2",
            "bs2",
            "loop0_phase",
            "loop1_phase",
            "loop2_phase",
        ]
        params = dict(zip(names, params))
        prog = borealis_device.create_program(**params)

        reset_compiler(self.target)

        prog.compile(compiler="borealis")
Пример #2
0
    def test_compile(self):
        """Test that a program can be compiled correctly using the Borealis compiler"""
        gate_args = borealis_gbs(borealis_device)
        prog = self.borealis_program(gate_args)
        reset_compiler(self.target)

        prog.compile(device=borealis_device)
Пример #3
0
    def test_compile_with_integer_phases(self):
        """Test that a program can be compiled correctly using the Borealis compiler and integer valued phases"""
        gate_args = borealis_gbs(borealis_device)
        gate_args[1] = [1] * len(
            gate_args[1]
        )  # exchange the phase-gate arguments with integer values
        prog = self.borealis_program(gate_args)
        reset_compiler(self.target)

        prog.compile(device=borealis_device)
Пример #4
0
    def test_compile_error_without_devicespec(self):
        """Test the correct error is raised when the tdm circuit is compiled
        without a device specification"""
        gate_args = borealis_gbs(borealis_device)
        prog = self.borealis_program(gate_args)
        reset_compiler(self.target)

        with pytest.raises(
                CircuitError,
                match=
                "TDM programs cannot be compiled without a valid circuit layout"
        ):
            prog.compile(compiler=self.target)
Пример #5
0
    def test_loop_compensation_warning(self, caplog):
        """Test that a program logs the correct warning when loop offset compensation takes place."""
        gate_args = borealis_gbs(borealis_device)
        assert isinstance(gate_args, list)

        prog = self.borealis_program(gate_args)
        reset_compiler(self.target)

        caplog.clear()
        match = "have been shifted by pi in order to be compatible with the phase modulators"
        with caplog.at_level(logging.WARNING):
            prog.compile(device=borealis_device)
        assert match not in caplog.text
Пример #6
0
    def test_compile_error_invalid_loop_offset_name(self):
        """Test the correct error is raised when the tdm circuit is compiled
        with a device specification having incorrectly named loop offsets"""
        invalid_spec = copy.deepcopy(borealis_device._spec)
        invalid_spec["layout"] = invalid_spec["layout"].replace(
            "loop1_phase", "loop1_phase42")
        invalid_device = Device(spec=invalid_spec,
                                cert=borealis_device.certificate)

        gate_args = borealis_gbs(invalid_device)
        prog = self.borealis_program(gate_args)
        reset_compiler(self.target)

        with pytest.raises(
                ValueError,
                match=
                "Expected single integer as part of name, got 'loop1_phase42'"
        ):
            prog.compile(device=invalid_device)
Пример #7
0
    def test_compile_incompatible_topology(self):
        """Test that a program raises the correct error when using an invalid circuit
        with the Borealis compiler"""
        gate_args = borealis_gbs(borealis_device)

        prog = self.borealis_program(gate_args)
        assert isinstance(prog.circuit, list)
        assert isinstance(prog.circuit[0].op, ops.Sgate)

        # change Sgate to an Rgate (applied to the same modes)
        prog.circuit[0].op = ops.Rgate(0.12)
        reset_compiler(self.target)

        # should raise error inside of `Borealis.compile()`
        with pytest.raises(
                CircuitError,
                match="Compilation not possible due to incompatible topologies."
        ):
            prog.compile(device=borealis_device)