Skip to content

Commit

Permalink
Update project file
Browse files Browse the repository at this point in the history
And some minor updates to examples.
  • Loading branch information
chemix-lunacy committed Oct 1, 2024
1 parent 00a899b commit 84a3844
Show file tree
Hide file tree
Showing 9 changed files with 1,290 additions and 535 deletions.
9 changes: 3 additions & 6 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
## Examples

**Running examples without building Rasqal:** Install [poetry](https://python-poetry.org/) and do `poetry install` in `rasqal/examples` or pip install the dependencies listed in the .toml file.
**Running examples without building Rasqal:** Install [poetry](https://python-poetry.org/) and do `poetry install` in `rasqal/examples` which will set up the venv for you. You can then run `run python examples.py` to just run the script or use your favourite IDE to debug.

If you've already built Rasqal via its build script its venv will have all the dependencies necessary so re-use that.

Note: all our examples are built using the old Q# compiler as Rasqal can exploit its fully interwoven classical LLVM instructions.

**Examples.py** holds runnable examples


runnable examples of many of Rasqals internal test projects showing how you set up and run things, including backend and argument definition. Shows the Q# that the QIR was generated from for each example, along with tertiary information.
Source for most examples can be found in `src/tests/qsharp` and can be modified from there and re-built.
**Examples.py** holds runnable examples of Rasqal including returned value, arguments, and custom backends.
Source for most examples can be found in `src/tests/qsharp`.

**Sandbox.py** runs the sandbox Q# project in `qsharp/src`. This uses the new Q# compiler so instruction set is limited.
11 changes: 5 additions & 6 deletions examples/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def basic_loops():
}
"""
print(f"Running basic-loops.")
# TODO: Check execution path, something slightly wrong here.
runner = fetch_runner(4)
results = runner.run_ll(read_qir_file("basic-loops.ll"), [5])
print(f"Returned {results}")
Expand Down Expand Up @@ -201,9 +200,9 @@ def qaoa():
runner.run_ll(read_qir_file("qaoa.ll"))


base_profile_bell()
full_bell()
basic_branching()
# base_profile_bell()
# full_bell()
# basic_branching()
basic_loops()
nested_calls()
qaoa()
# nested_calls()
# qaoa()
796 changes: 796 additions & 0 deletions examples/poetry.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions examples/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[project]
name = "rasqal_examples"
[tool.poetry]
name = "rasqal-examples"
version = "0.0.1"
requires-python = ">=3.10"
description = "A hybrid quantum-classical analysis/solving runtime."
description = "Code examples for Rasqal."
authors = []

dependencies = [
"rasqal>=1.6"
]
[tool.poetry.dependencies]
python = "~=3.10"
rasqal = "~=0.1.6"
qsharp = "~=1.9.0"

[project.urls]
Repository = "https://github.com/oqc-community/rasqal.git"
Issues = "https://github.com/oqc-community/rasqal/issues"
[[tool.poetry.source]]
name = "PyPI"
priority = "primary"
472 changes: 230 additions & 242 deletions examples/qir/basic-loops.ll

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions examples/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def run_sandbox():
# So Namespace.EntryMethod(...) will then generate the QIR you want.
sandbox = qsharp.compile("Sandbox.Main()")

runtime = TracingRuntime()

runner = RasqalRunner(runtime)
runner = RasqalRunner(TracingRuntime())
results = runner.run_ll(str(sandbox))

print(f"Sandbox results: {results}")
Expand Down
10 changes: 0 additions & 10 deletions src/scripts/psakefile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ task check -depends check-licenses
task format -depends format-rust, format-python
task pypi-build -depends build, audit-rasqal, check

# Task should not be invoked if you're building and installing Rasqal locally.
task initialize-examples -depends install-rasqal-from-pypi, setup-examples, run-examples

task format-python {
Invoke-LoggedCommand -workingDirectory $Root {
pip install ruff
Expand Down Expand Up @@ -89,13 +86,6 @@ task test-rasqal -depends build-rasqal {
}
}

# Used to install and run the examples without building Rasqal fully.
task install-rasqal-from-pypi -depends check-environment {
Invoke-LoggedCommand -workingDirectory $Root {
pip install rasqal
}
}

task setup-examples -depends check-environment {
# Install required dependencies.
Invoke-LoggedCommand -workingDirectory $Root {
Expand Down
31 changes: 15 additions & 16 deletions src/tests/qsharp/basic-loops/Library.qs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@

@EntryPoint()
operation Run(numSegments: Int) : Int {
use reg = Qubit[3];
ApplyToEach(H, reg);

mutable incrementing_result = 0;
for index in 0..numSegments {
ApplyToEach(H, reg);
use reg = Qubit[3] {
ApplyToEach(H, reg);

// Would use modulo here but need to add it to allowed instructions.
let is_even = index == 2 || index == 4 || index == 6 || index == 8 || index == 10;
if is_even {
H(reg[0]);
H(reg[2]);
}
// Would use modulo here but need to add it to allowed instructions.
let is_even = index == 2 || index == 4 || index == 6 || index == 8 || index == 10;
if is_even {
H(reg[0]);
H(reg[2]);
}

let result = ResultArrayAsBoolArray(MultiM(reg));
mutable appending = 0;
if result[0] { set appending = appending + 1; }
if result[1] { set appending = appending + 1; }
if result[2] { set appending = appending + 1; }
let result = ResultArrayAsBoolArray(MultiM(reg));
mutable appending = 0;
if result[0] { set appending = appending + 1; }
if result[1] { set appending = appending + 1; }
if result[2] { set appending = appending + 1; }

set incrementing_result = incrementing_result + appending;
set incrementing_result = incrementing_result + appending;
}
}

return incrementing_result * 5;
Expand Down
Loading

0 comments on commit 84a3844

Please sign in to comment.