Skip to content

Release 0.14.0

Compare
Choose a tag to compare
@josh146 josh146 released this 05 May 03:33
· 277 commits to master since this release

New features since last release

  • The "tf" backend now supports TensorFlow 2.0 and above. (#283) (#320) (#323) (#361) (#372) (#373) (#374) (#375) (#377)

    For more details and demonstrations of the new TensorFlow 2.0-compatible backend, see our optimization and machine learning tutorials.

    For example, using TensorFlow 2.0 to train a variational photonic circuit:

    eng = sf.Engine(backend="tf", backend_options={"cutoff_dim": 7})
    prog = sf.Program(1)
    
    with prog.context as q:
        # Apply a single mode displacement with free parameters
        Dgate(prog.params("a"), prog.params("p")) | q[0]
    
    opt = tf.keras.optimizers.Adam(learning_rate=0.1)
    
    alpha = tf.Variable(0.1)
    phi = tf.Variable(0.1)
    
    for step in range(50):
        # reset the engine if it has already been executed
        if eng.run_progs:
            eng.reset()
    
        with tf.GradientTape() as tape:
            # execute the engine
            results = eng.run(prog, args={'a': alpha, 'p': phi})
            # get the probability of fock state |1>
            prob = results.state.fock_prob([1])
            # negative sign to maximize prob
            loss = -prob
    
        gradients = tape.gradient(loss, [alpha, phi])
        opt.apply_gradients(zip(gradients, [alpha, phi]))
        print("Value at step {}: {}".format(step, prob))
  • Adds the method number_expectation that calculates the expectation value of the product of the number operators of a given set of modes. (#348)

    prog = sf.Program(3)
    with prog.context as q:
        ops.Sgate(0.5) | q[0]
        ops.Sgate(0.5) | q[1]
        ops.Sgate(0.5) | q[2]
        ops.BSgate(np.pi/3, 0.1) |  (q[0], q[1])
        ops.BSgate(np.pi/3, 0.1) |  (q[1], q[2])

    Executing this on the Fock backend,

    >>> eng = sf.Engine("fock", backend_options={"cutoff_dim": 10})
    >>> state = eng.run(prog).state

    we can compute the expectation value <n_0 n_2>:

    >>> state.number_expectation([0, 2])

Improvements

  • Add details to the error message for failed remote jobs. (#370)

  • The required version of The Walrus was increased to version 0.12, for
    tensor number expectation support. (#380)

Contributors

This release contains contributions from (in alphabetical order):

Tom Bromley, Theodor Isacsson, Josh Izaac, Nathan Killoran, Filippo Miatto, Nicolás Quesada, Antal Száva, Paul Tan.