Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Swift console app sample #9

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading