Skip to content

Commit

Permalink
Merge pull request #9 from qsharp-community/feature/swift
Browse files Browse the repository at this point in the history
added Swift console app sample
  • Loading branch information
filipw authored Jun 25, 2024
2 parents e3637ec + b8819a7 commit 2059889
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ bin/
obj/
bindings
.DS_Store
examples/swift/console/deps
qsharp-bridge-swift-sample
38 changes: 38 additions & 0 deletions examples/swift/console/main.swift
Original file line number Diff line number Diff line change
@@ -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")
}
}
14 changes: 14 additions & 0 deletions examples/swift/console/run.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2059889

Please sign in to comment.