예제 #1
0
    def test_use_template(self):
        """Test templates can be initialized"""
        bb = BlackbirdProgram(name="prog", version=0.0)
        x = sym.Symbol('x')
        hi = sym.Symbol('hi')
        bb._parameters = [str(x), str(hi)]
        bb._operations.append({
            "op": "Dgate",
            "modes": [0],
            "args": [0.54 / x**2],
            "kwargs": {
                'test': hi**4
            }
        })
        bb._operations.append({
            "op": "Sgate",
            "modes": [0],
            "args": [0.543],
            "kwargs": {}
        })
        bb._operations.append({"op": "Sgate", "modes": [0]})

        assert bb.parameters == {'x', 'hi'}
        assert bb.is_template()

        bb2 = bb(x=5, hi=2)
        assert not bb2.parameters
        assert not bb2.is_template()
        assert bb2.operations[0]["args"] == [0.54 / 5**2]
        assert bb2.operations[0]["kwargs"] == {'test': 2**4}
        assert bb.operations[1] == bb2.operations[1]
예제 #2
0
    def test_initialization(self):
        """Test all attributes correctly initialized"""
        bb = BlackbirdProgram(name="prog", version=0.0)
        assert not bb._var

        assert bb.name == "prog"
        assert bb.version == 0.0
        assert not bb.modes

        assert bb.target["name"] is None
        assert not bb.target["options"]
        assert not bb.operations

        assert not len(bb)

        assert not bb.is_template()
        assert not bb.parameters