Coder Social home page Coder Social logo

Comments (1)

dbwz8 avatar dbwz8 commented on September 2, 2024

Yes. This is expected behavior. You cannot nest Circuit.Compile, Circuit.Run or Circuit.Fold. The standard technique is do each of these once. Here is a version of your code as an fsx script in samples:

#if INTERACTIVE
#I @"..\bin"         // Tell fsi where to find the Liquid dll
#r "Liquid1.dll"                 
#r "Liquid2.dll"                 
#else
namespace Microsoft.Research.Liquid // Tell the compiler our namespace
#endif

open System                         // Open any support libraries

open Microsoft.Research.Liquid      // Get necessary Liquid libraries
open Util                           // General utilites
open Operations                     // Basic gates and operations
open Tests                          // Just gets us the RenderTest call for dumping files

module Script =                     // The script module allows for incremental loading

    [<LQD>]                         // LQD flags this as being callable from the command line
    let Main() =                    // Name of callable function

        logOpen "Liquid.log" false
        show "Starting sample script..."    // show does printf + logs and ensemble runs

        let k = Ket(4)
        let qs = k.Qubits
        let expand (qs: Qubits) =
            match (List.map(fun l -> [l]) qs) with
            | [_;_;_;_] ->

                let labellingStart (qbs: Qubits) =
                    LabelL "\\ket{k_i}" [qbs.[3]]
                    LabelL "\\ket{k_{i+1}}" [qbs.[2]]
                    LabelL "\\ket{k_{i+2}}" [qbs.[1]]
                    LabelL "\\ket{k_{i+3}}" [qbs.[0]]

                labellingStart qs

                // ... Remainder of circuit function ....
                H >< qs
                M >< qs
                
            | x -> failwithf "4 qubits must be given, instead was given %A" x
        let circ = Circuit.Compile expand qs
        let circ = circ.Fold()
        circ.RenderHT "Test"
        
#if INTERACTIVE
do Script.Main()        // If interactive, then run the routine automatically
#endif

This will generate a drawing of the circuit as "Test.htm" (and Test.tex). What you really want to do comes under the area of Circuit manipulation. You can take any function and compile it to a circuit (as well as fold it). If you made your labels in one circuit and your real algorithm in one (or more) other compiled circuits, then you could just walk the circuit data structure and splice them together (this functionality is not built into the system).

If you take a look in the kit at \Liquid\UserCode\DaveWecker\AltOutput.fs you'll see an example where I programmatically walk the circuit data structure to emit QASM code. you could just walk your separate circuits to generate a single new one for execution or rendering.

from liquid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.