Skip to content
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
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pixi run plot # Run benchmarks and plot their results in data/
from qlabs.base import StateVector, Hadamard, SWAP, NOT, PauliY, PauliZ
from qlabs.abstractions import GateCircuit, StateVectorSimulator, ShowAfterEachGate

num_qubits = 3
alias num_qubits = 3
qc = GateCircuit(num_qubits)

qc.apply_gates(
Expand All @@ -92,11 +92,31 @@ print("Quantum circuit created:\n", qc) # Visualization not fully implemented
qsimu = StateVectorSimulator(
qc,
initial_state=StateVector.from_bitstring("0" * num_qubits),
use_gpu_if_available=True, # GPU support not fully implemented
use_gpu_if_available=False,
verbose=True,
verbose_step_size=ShowAfterEachGate, # Options: ShowAfterEachGate, ShowOnlyEnd
)

# GPU usage
# The StateVectorSimulator currently does not support GPU with control gates fully.
# The lower-level function `qubit_wise_multiply()` is correctly implemented for GPU.
# qsimu = StateVectorSimulator[
# gpu_num_qubits=num_qubits,
# gpu_gate_ordered_set= [Hadamard, NOT, PauliY, PauliZ],
# gpu_control_gate_count=3, # Planned to be automated
# gpu_control_bits_list= [
# [[2, 0]],
# [[1, 1]],
# [[0, 1]],
# ], # Planned to be automated
# ](
# qc,
# initial_state=StateVector.from_bitstring("0" * num_qubits),
# use_gpu_if_available=True,
# verbose=True,
# verbose_step_size=ShowOnlyEnd,
# )

final_state = qsimu.run()

print("Final quantum state:\n", final_state)
Expand Down
17 changes: 10 additions & 7 deletions examples/circuit_level.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,27 @@ fn simulate_figure1_circuit_abstract() -> None:
# Create the initial state |000⟩
initial_state: StateVector = StateVector.from_bitstring("000")

# Simulating using CPU
qsimu = StateVectorSimulator(
qc,
initial_state=initial_state,
use_gpu_if_available=True,
use_gpu_if_available=False,
verbose=True,
verbose_step_size=ShowOnlyEnd, # ShowAfterEachGate, ShowAfterEachLayer
verbose_step_size=ShowOnlyEnd, # or ShowAfterEachGate, ShowAfterEachLayer
)

# # For GPU (NOTE: Doesn't work currently as GPU doesn't fully support control bits)
# # Simulating using GPU
# qsimu = StateVectorSimulator[
# gpu_num_qubits=num_qubits,
# gpu_gate_ordered_set= [Hadamard, PauliZ, NOT],
# gpu_control_gate_count=2,
# gpu_control_bits_list= [[[1, 1], [1, 1]]],
# gpu_control_bits_list= [[[1, 1]], [[1, 1]]],
# ](
# qc,
# initial_state=initial_state,
# use_gpu_if_available=True,
# verbose=True,
# verbose_step_size=ShowOnlyEnd, # ShowAfterEachGate, ShowAfterEachLayer
# verbose_step_size=ShowOnlyEnd,
# )

state = qsimu.run()
Expand Down Expand Up @@ -122,7 +123,9 @@ fn simulate_figure4_circuit_abstract() -> None:
print("Final quantum state:\n", final_state)


fn simulate_random_circuit[number_qubits: Int](number_layers: Int) -> None:
fn simulate_random_circuit[
number_qubits: Int, use_gpu: Bool = True
](number_layers: Int) -> None:
"""Simulates a random quantum circuit with the specified number of qubits and layers.

Parameters:
Expand Down Expand Up @@ -167,7 +170,7 @@ fn simulate_random_circuit[number_qubits: Int](number_layers: Int) -> None:
](
qc,
initial_state=quantum_state,
use_gpu_if_available=True,
use_gpu_if_available=use_gpu,
verbose=False,
)

Expand Down
4 changes: 3 additions & 1 deletion examples/main.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def main():

print("=========================================")
print("circuit_level: simulate_random_circuit()")
simulate_random_circuit[number_qubits=20](number_layers=5)
simulate_random_circuit[number_qubits=20, use_gpu=True](
number_layers=5,
)

print("=========================================")
print("circuit_level: simulate_figure4_circuit_abstract()")
Expand Down
Binary file modified img/benchmark_H100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.