diff --git a/.gitignore b/.gitignore index ce10b4d..efd8496 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ bin/ obj/ bindings .DS_Store +examples/swift/console/deps +qsharp-bridge-swift-sample diff --git a/examples/swift/console/main.swift b/examples/swift/console/main.swift new file mode 100644 index 0000000..524742b --- /dev/null +++ b/examples/swift/console/main.swift @@ -0,0 +1,38 @@ +import qsharp_bridgeFFI + +let qsharpSource = """ +namespace MyQuantumApp { + @EntryPoint() + operation Main() : Unit { + use q = Qubit(); + H(q); + let result = MResetZ(q); + Message($"{result}"); + } +} +""" + +print("Shots: 10") + +let resultShots = try! runQsShots(source: qsharpSource, shots: 10) + +for i in 0..<10 { + print() + print("Shot \(i+1) of 10") + printOutcome(resultShots[i]) + print() +} + +func printOutcome(_ result: ExecutionState) { + print("Messages:") + for msg in result.messages { + print(" \(msg)") + } + + print("Output:") + if let resultValue = result.result { + print(" \(resultValue)") + } else { + print(" No result available") + } +} \ No newline at end of file diff --git a/examples/swift/console/run.sh b/examples/swift/console/run.sh new file mode 100755 index 0000000..2d04d57 --- /dev/null +++ b/examples/swift/console/run.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +rm -rf deps +rm -f qsharp-bridge-swift-sample +mkdir -p deps + +cargo build --release +cp ../../../target/release/libqsharp_bridge.a deps/ +cp ../../../bindings/qsharp_bridge.swift deps/ +cp ../../../bindings/qsharp_bridgeFFI.h deps/ +cp ../../../bindings/qsharp_bridgeFFI.modulemap deps/ +swiftc *.swift deps/*.swift -I./deps -L./deps -lqsharp_bridge -Xcc -fmodule-map-file=$(pwd)/deps/qsharp_bridgeFFI.modulemap -o qsharp-bridge-swift-sample + +./qsharp-bridge-swift-sample \ No newline at end of file