Example #1
0
    def test_parse_string(self):
        """Test that device name is extracted"""
        bb = parse(antlr4.InputStream(test_file))

        assert bb._var == {"alpha": 0.3423}

        expected = {
            "name": "fock",
            "options": {
                "num_subsystems": 1,
                "cutoff_dim": 7,
                "shots": 10
            }
        }
        assert bb.target == expected

        expected = [
            {
                "op": "Coherent",
                "args": [0.3423, np.sqrt(np.pi)],
                "kwargs": {},
                "modes": [0]
            },
            {
                "op": "MeasureFock",
                "args": [],
                "kwargs": {},
                "modes": [0]
            },
        ]

        assert bb.operations == expected
Example #2
0
    def test_parse_file(self, tmpdir):
        """Test that device name is extracted"""
        filename = tmpdir.join("test.xbb")

        with open(filename, "w") as f:
            f.write(test_file)

        bb = parse(antlr4.FileStream(filename))

        assert bb._var == {"alpha": 0.3423}

        expected = {"name": "fock", "options": {"num_subsystems": 1, "cutoff_dim": 7, "shots": 10}}
        assert bb.target == expected

        expected = [
            {"op": "Coherent", "args": [0.3423, np.sqrt(np.pi)], "kwargs": {}, "modes": [0]},
            {"op": "MeasureFock", "args": [], "kwargs": {}, "modes": [0]},
        ]

        assert bb.operations == expected