Download LIQUiD Users Manual
Transcript
S E R I O U S C O D I N G H qs let q0 = qs.Head for i in 1..qs.Length-1 do CNOT !!(qs,0,i) M >< qs // Measure all the qubits Example 10: Single Entanglement circuit We’ve made use of another built-in helper function (!!) which will pull out the indexed qubits from a list and create a new list. If we call ops directly, we will get the exact results we saw in Entangle1. However, we can turn this into a circuit data structure and then execute the data structure: let circ = Circuit.Compile ops qs circ.Run qs let circ2 = circ.GrowGates(ket) circ2.Run qs // Compile and run circuit // Optimize and run circuit Example 11: Circuit Compilation and running The circuit is actually slightly slower than the direction function calls. However, circuits are useful for many purposes. Since they are a data structure, the can be analyzed, modified, optimized, replaced, rendered as drawings, exported to other systems and simply run as if they were the original circuit. The second two lines in the example create an optimized version of the circuit. Here’s what happens when we run all three variants: 0:0000.0/ Secs/Op 0:0000.0/ ------0:0000.2/ 11.474 0:0000.2/ 0.952 0:0000.4/ 12.746 0:0000.5/ 0.878 0:0000.5/ 2.330 S/Qubit ------11.474 0.952 12.746 0.878 2.330 Mem(GB) ------0.419 0.366 0.419 0.544 0.362 Operation --------Straight function calls Compile cost Compiled circuit run time Optimization cost Optimized circuit run time Example 12: Entangle1 with optimization run times Here you can see that the compiled circuit is slightly slower, but the optimized version is ~5 times faster. LIQ𝑈𝑖|⟩ contains a large number of user accessible optimizations to make quantum simulations as efficient as possible. To see the generated circuit, we could call the Dump command: circ.Dump(showLogInd) Example 13: Dump of Teleport Circuit The Dump command is defined throughout the system on most LIQ𝑈𝑖|⟩ data types and may be nested. For this reason it takes up to two arguments: a dumping function (showLogInd) which writes the output to the log in an indented manner and a starting indentation level (showInd will output to the log and the console). The result for Entangle2(2) is: Circuit dump (in Liquid.log): SEQ 20 Copyright © 2015 by Microsoft Corporation. All Rights Reserved.