Skip to content
Draft
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
6 changes: 5 additions & 1 deletion devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@
extraPackages = with pkgs.python3Packages; [
types-pyyaml
];
excludes = ["selene-sim/python/tests"];
excludes = [
"selene-sim/python/tests"
"selene-ext/simulators/quest/python/gate_definitions.py"
"selene-ext/simulators/stim/python/gate_definitions.py"
];
};
};
};
Expand Down
69 changes: 69 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def initialize(self, version: str, build_data: dict) -> None:
cargo_runner.run()
self.build_selene_c_interface()
self.build_helios_qis()
self.build_sol_qis()

packages = [Path("selene-sim/python/selene_sim")]
for topic_dir in Path("selene-ext").iterdir():
Expand Down Expand Up @@ -230,6 +231,10 @@ def distribute_cargo_artifacts(self):
self.app.display_info(f"Copying {lib} to {self.install_lib_dir}")
shutil.copy(lib, self.install_lib_dir)
lib_paths.append(lib)
for lib in self.find_release_files("sol_selene_interface"):
self.app.display_info(f"Copying {lib} to {self.install_lib_dir}")
shutil.copy(lib, self.install_lib_dir)
lib_paths.append(lib)

return lib_paths

Expand Down Expand Up @@ -354,3 +359,67 @@ def build_helios_qis(self):
sys.exit(1)

self.app.display_success("Helios QIS build completed successfully")

def build_sol_qis(self):
self.app.display_mini_header("Building Sol QIS")
sol_qis_dir = Path(self.root) / "selene-ext/interfaces/sol_qis"
cmake_build_dir = sol_qis_dir / "c/build"
cmake_build_dir.mkdir(parents=True, exist_ok=True)
dist_dir = sol_qis_dir / "python/selene_sol_qis_plugin/_dist"
dist_dir.mkdir(parents=True, exist_ok=True)
selene_sim_dist_dir = Path(self.root) / "selene-sim/python/selene_sim/_dist"

try:
subprocess.run(
[
"cmake",
f"-DCMAKE_INSTALL_PREFIX={dist_dir}",
"-DCMAKE_BUILD_TYPE=Release",
f"-DCMAKE_PREFIX_PATH={selene_sim_dist_dir}",
"..",
],
cwd=cmake_build_dir,
check=True,
capture_output=True,
)
except subprocess.CalledProcessError as e:
if b"is different than the directory" not in e.stderr:
self.app.display_error(f"cmake failed: {e.stderr.decode()}")
sys.exit(1)
try:
# existing build dir is incompatible, delete and retry
shutil.rmtree(cmake_build_dir)
cmake_build_dir.mkdir()
subprocess.run(
[
"cmake",
f"-DCMAKE_INSTALL_PREFIX={dist_dir}",
f"-DCMAKE_PREFIX_PATH={selene_sim_dist_dir}",
"..",
],
cwd=cmake_build_dir,
check=True,
capture_output=True,
)
except subprocess.CalledProcessError as e:
self.app.display_error(f"cmake failed: {e.stderr.decode()}")
sys.exit(1)

try:
subprocess.run(
[
"cmake",
"--build",
".",
"--target",
"install",
],
check=True,
cwd=cmake_build_dir,
capture_output=True,
)
except subprocess.CalledProcessError as e:
self.app.display_error(f"cmake build failed: {e.stderr.decode()}")
sys.exit(1)

self.app.display_success("Sol QIS build completed successfully")
11 changes: 4 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dev = [
[tool.uv.sources]
selene-sim = { workspace = true }
selene-core = { workspace = true }
selene-hugr-qis-compiler = { path = "../tket2/dist/selene_hugr_qis_compiler-0.2.10-cp310-abi3-linux_x86_64.whl" }

[tool.uv.workspace]
members = ["selene-core"]
Expand All @@ -78,6 +79,7 @@ packages = [
"selene-ext/error-models/ideal/python/selene_ideal_error_model_plugin",
"selene-ext/error-models/simple-leakage/python/selene_simple_leakage_error_model_plugin",
"selene-ext/interfaces/helios_qis/python/selene_helios_qis_plugin",
"selene-ext/interfaces/sol_qis/python/selene_sol_qis_plugin",
"selene-ext/runtimes/simple/python/selene_simple_runtime_plugin",
"selene-ext/runtimes/soft_rz/python/selene_soft_rz_runtime_plugin",
"selene-ext/simulators/classical-replay/python/selene_classical_replay_plugin",
Expand Down Expand Up @@ -105,9 +107,7 @@ cache-keys = [

[tool.ruff]
# exclude any external code (e.g. stim) fetched in the build process
extend-exclude = [
"target",
]
extend-exclude = ["target"]
[tool.ruff.lint.per-file-ignores]
"**/python/tests/*.py" = ["F821", "F841"] # ^

Expand Down Expand Up @@ -138,10 +138,7 @@ known_first_party = [
"selene_quest_plugin",
"selene_stim_plugin",
]
extend_exclude = [
"target",
"selene-core/python/selene_core",
]
extend_exclude = ["target", "selene-core/python/selene_core"]

[tool.deptry.package_module_name_map]
pyyaml = "yaml"
Expand Down
38 changes: 27 additions & 11 deletions selene-core/c/include/selene/core_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,6 @@ typedef void *SeleneRuntimeGetOperationInstance;
* first parameter.
*/
typedef struct SeleneRuntimeGetOperationInterface {
void (*rzz_fn)(SeleneRuntimeGetOperationInstance,
uint64_t,
uint64_t,
double);
void (*rxy_fn)(SeleneRuntimeGetOperationInstance,
uint64_t,
double,
double);
void (*rz_fn)(SeleneRuntimeGetOperationInstance,
uint64_t,
double);
void (*measure_fn)(SeleneRuntimeGetOperationInstance,
uint64_t,
uint64_t);
Expand All @@ -130,6 +119,33 @@ typedef struct SeleneRuntimeGetOperationInterface {
void (*set_batch_time_fn)(SeleneRuntimeGetOperationInstance,
uint64_t,
uint64_t);
void (*rzz_fn)(SeleneRuntimeGetOperationInstance,
uint64_t,
uint64_t,
double);
void (*rxy_fn)(SeleneRuntimeGetOperationInstance,
uint64_t,
double,
double);
void (*rz_fn)(SeleneRuntimeGetOperationInstance,
uint64_t,
double);
void (*twin_rxy_gate)(SeleneRuntimeGetOperationInstance,
uint64_t,
uint64_t,
double,
double);
void (*rpp_gate)(SeleneRuntimeGetOperationInstance,
uint64_t,
uint64_t,
double,
double);
void (*tk2_gate)(SeleneRuntimeGetOperationInstance,
uint64_t,
uint64_t,
double,
double,
double);
} SeleneRuntimeGetOperationInterface;

typedef void *SeleneRuntimeExtractOperationInstance;
Expand Down
58 changes: 58 additions & 0 deletions selene-core/c/include/selene/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ int32_t selene_runtime_global_barrier(RuntimeInstance instance,

/**
* Instruct the runtime to apply an RXY gate to the qubit with the given ID.
* It might not be supported by all runtimes, and an error will be returned
* if it is used on a runtime that does not support it, or if the runtime
* is unable to apply it for any reason.
*
* Note that it is up to the runtime whether or not this gate is applied immediately:
* The runtime might act lazily and apply the gate at a later time when an observable
* outcome is requested.
Expand All @@ -197,6 +201,10 @@ int32_t selene_runtime_rxy_gate(RuntimeInstance instance,

/**
* Instruct the runtime to apply an RZZ gate to the qubits with the given IDs.
* It might not be supported by all runtimes, and an error will be returned
* if it is used on a runtime that does not support it, or if the runtime
* is unable to apply it for any reason.
*
* Note that it is up to the runtime whether or not this gate is applied
* immediately: The runtime might act lazily and apply the gate at a later time.
*/
Expand All @@ -207,6 +215,10 @@ int32_t selene_runtime_rzz_gate(RuntimeInstance instance,

/**
* Instruct the runtime to apply an RZ gate to the qubit with the given ID.
* It might not be supported by all runtimes, and an error will be returned
* if it is used on a runtime that does not support it, or if the runtime
* is unable to apply it for any reason.
*
* Note that it is up to the runtime whether or not this gate is applied
* immediately: The runtime might act lazily and apply the gate at a later time.
* It might not apply it at all, as RZ may be elided in code.
Expand All @@ -215,6 +227,52 @@ int32_t selene_runtime_rz_gate(RuntimeInstance instance,
uint64_t qubit_id,
double theta);

/**
* Instruct the runtime to apply a TwinRXY gate to the qubits with the given IDs.
* It might not be supported by all runtimes, and an error will be returned
* if it is used on a runtime that does not support it, or if the runtime
* is unable to apply it for any reason.
*
* Note that it is up to the runtime whether or not this gate is applied
* immediately: The runtime might act lazily and apply the gate at a later time.
*/
int32_t selene_runtime_twin_rxy_gate(RuntimeInstance instance,
uint64_t qubit_id_1,
uint64_t qubit_id_2,
double theta,
double phi);

/**
* Instruct the runtime to apply an RPP gate to the qubits with the given IDs.
* It might not be supported by all runtimes, and an error will be returned
* if it is used on a runtime that does not support it, or if the runtime
* is unable to apply it for any reason.
*
* Note that it is up to the runtime whether or not this gate is applied
* immediately: The runtime might act lazily and apply the gate at a later time.
*/
int32_t selene_runtime_rpp_gate(RuntimeInstance instance,
uint64_t qubit_id_1,
uint64_t qubit_id_2,
double theta,
double phi);

/**
* Instruct the runtime to apply a TK2 gate to the qubits with the given IDs.
* It might not be supported by all runtimes, and an error will be returned
* if it is used on a runtime that does not support it, or if the runtime
* is unable to apply it for any reason.
*
* Note that it is up to the runtime whether or not this gate is applied
* immediately: The runtime might act lazily and apply the gate at a later time.
*/
int32_t selene_runtime_tk2_gate(RuntimeInstance instance,
uint64_t qubit_id_1,
uint64_t qubit_id_2,
double alpha,
double beta,
double gamma);

/**
* Instruct the runtime that a measurement is to be requested and to write
* a reference ID to the result to the `result` pointer.
Expand Down
32 changes: 32 additions & 0 deletions selene-core/c/include/selene/simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,38 @@ int32_t selene_simulator_operation_rz(SeleneSimulatorInstance instance,
uint64_t qubit,
double theta);

/**
* Apply a TK2 (aka SU(4)) gate to the qubits at the requested indices,
* with the provided angles. This gate performs the canonical two-qubit
* interaction characterized by the three angles alpha, beta, and gamma.
*/
int32_t selene_simulator_operation_tk2(SeleneSimulatorInstance instance,
uint64_t qubit1,
uint64_t qubit2,
double alpha,
double beta,
double gamma);

/**
* Apply a Twin RXY gate to the qubits at the requested indices, with the
* provided angles. This gate performs simultaneous RXY rotations on both qubits.
*/
int32_t selene_simulator_operation_twin_rxy(SeleneSimulatorInstance instance,
uint64_t qubit1,
uint64_t qubit2,
double theta,
double phi);

/**
* Apply an RPP gate to the qubits at the requested indices, with the
* provided angles.
*/
int32_t selene_simulator_operation_rpp(SeleneSimulatorInstance instance,
uint64_t qubit1,
uint64_t qubit2,
double theta,
double phi);

/**
* Measure the qubit at the requested index. This is a destructive
* operation.
Expand Down
29 changes: 29 additions & 0 deletions selene-core/python/selene_core/build_utils/builtins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@
HeliosObjectFileToSeleneExecutableStep_Darwin,
register_helios_builtins,
)
from .sol import (
SolLLVMIRStringKind,
SolLLVMIRFileKind,
SolLLVMBitcodeStringKind,
SolLLVMBitcodeFileKind,
SolObjectFileKind,
SolLLVMBitcodeStringToSolLLVMBitcodeFileStep,
SolLLVMIRStringToSolLLVMIRFileStep,
SolLLVMIRFileToSolObjectFileStep,
SolLLVMBitcodeFileToSolObjectFileStep,
SolObjectFileToSeleneObjectFileStep_Linux,
SolObjectFileToSeleneExecutableStep_Windows,
SolObjectFileToSeleneExecutableStep_Darwin,
register_sol_builtins,
)

from .qir import (
QIRIRFileKind,
QIRIRStringKind,
Expand All @@ -63,6 +79,7 @@ def register_builtins(planner: BuildPlanner):
register_selene_builtins(planner)
register_hugr_builtins(planner)
register_helios_builtins(planner)
register_sol_builtins(planner)
register_qir_builtins(planner)


Expand Down Expand Up @@ -102,5 +119,17 @@ def register_builtins(planner: BuildPlanner):
"QIRIRFileToQIRBitcodeFileStep",
"QIRBitcodeFileToQIRBitcodeStringStep",
"QIRBitcodeStringToHeliosBitcodeStringStep",
"SolLLVMIRStringKind",
"SolLLVMIRFileKind",
"SolLLVMBitcodeStringKind",
"SolLLVMBitcodeFileKind",
"SolObjectFileKind",
"SolLLVMBitcodeStringToSolLLVMBitcodeFileStep",
"SolLLVMIRStringToSolLLVMIRFileStep",
"SolLLVMIRFileToSolObjectFileStep",
"SolLLVMBitcodeFileToSolObjectFileStep",
"SolObjectFileToSeleneObjectFileStep_Linux",
"SolObjectFileToSeleneExecutableStep_Windows",
"SolObjectFileToSeleneExecutableStep_Darwin",
"register_builtins",
]
Loading
Loading