示例#1
0
    def test_catstate_complex_error(self):
        """Test that passing a complex parameter to gates that previously accepted
        complex parameters raises an error."""
        with pytest.raises(ValueError, match="cannot be complex"):
            prog = Program(1)
            with prog.context as q:
                ops.Catstate(0.2 + 1j) | q

            eng = Engine("fock", backend_options={"cutoff_dim": 5})
            res = eng.run(prog)
示例#2
0
    def test_complex_first_argument_error(self, gate):
        """Test that passing a complex parameter to gates that previously accepted
        complex parameters raises an error."""
        with pytest.raises(ValueError, match="cannot be complex"):
            prog = Program(1)
            with prog.context as q:
                gate(0.2 + 1j) | q

            eng = Engine("gaussian")
            res = eng.run(prog)
示例#3
0
    def test_complex_symbolic(self, gate):
        """Test that passing a complex value to symbolic parameter of a gate
        that previously accepted complex parameters raises an error.

        An example here is testing heterodyne measurements.
        """
        with pytest.raises(ValueError, match="cannot be complex"):

            prog = Program(1)

            with prog.context as q:
                ops.MeasureHD | q[0]
                gate(q[0].par) | q

            eng = Engine("gaussian")
            res = eng.run(prog)
示例#4
0
def test_tf_batch_in_gates_previously_supporting_complex(gate):
    """Test if gates that previously accepted complex arguments support the input of TF tensors in
    batch form"""
    tf = pytest.importorskip("tensorflow")

    batch_size = 2
    prog = Program(1)
    eng = Engine(backend="tf",
                 backend_options={
                     "cutoff_dim": 3,
                     "batch_size": batch_size
                 })

    theta = prog.params("theta")
    _theta = tf.Variable([0.1] * batch_size)

    with prog.context as q:
        gate(theta) | q[0]

    eng.run(prog, args={"theta": _theta})
示例#5
0
def test_tf_batch_complex_raise(gate):
    """Test if an error is raised if complex TF tensors with a batch dimension are input for gates
    that previously accepted complex arguments"""
    tf = pytest.importorskip("tensorflow")

    batch_size = 2
    prog = Program(1)
    eng = Engine(backend="tf",
                 backend_options={
                     "cutoff_dim": 3,
                     "batch_size": batch_size
                 })

    theta = prog.params("theta")
    _theta = tf.Variable([0.1j] * batch_size)

    with prog.context as q:
        gate(theta) | q[0]

    with pytest.raises(ValueError, match="cannot be complex"):
        eng.run(prog, args={"theta": _theta})
示例#6
0
 def _setup_eng(num_subsystems):
     """Factory function"""
     eng, q = Engine(num_subsystems)
     eng.backend = setup_backend(num_subsystems)
     return eng, q