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

Team Duckbergs #6

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
32 changes: 32 additions & 0 deletions team-solutions/Duckbergs/1_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from bloqade import move
from iquhack_scoring import MoveScorer
import matplotlib.pyplot as plt
from kirin.passes import aggressive
from numpy import pi
from util import *

@move.vmove()
def ans1_1():
# Prepare
q = move.NewQubitRegister(3)
state = move.Init(
qubits=[q[0], q[1], q[2]],
indices=[0, 1, 2],
)

state.gate[[0,1,3]] = move.Move(state.storage[[0,1,2]])

state = move.GlobalCZ(atom_state=state)

state.gate[[2]] = move.Move(state.gate[[1]])
state = local_CX(atom_state=state, indices=[2])

move.Execute(state)

with open('./qasm/1.1.qasm', 'r') as file:
file_content = file.read()
aggressive.Fold(move.vmove)(ans1_1)
analysis = MoveScorer(ans1_1, expected_qasm=file_content)
score = analysis.score()
for key,val in score.items():
print(f"{key}: {val}")
51 changes: 51 additions & 0 deletions team-solutions/Duckbergs/1_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from bloqade import move
from iquhack_scoring import MoveScorer
import matplotlib.pyplot as plt
from kirin.passes import aggressive
from numpy import pi
from util import *

@move.vmove()
def ans1_2():
# Prepare
q = move.NewQubitRegister(3)
state = move.Init(
qubits=[q[0], q[1], q[2]],
indices=[0, 1, 2],
)

state.gate[[0,2,3]] = move.Move(state.storage[[0,1,2]])

state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[3], theta=-pi/4)
state.gate[[1]] = move.Move(state.gate[[2]])
state.gate[[2]] = move.Move(state.gate[[0]])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[3], theta=pi/4)
state.gate[[0]] = move.Move(state.gate[[2]])
state.gate[[2]] = move.Move(state.gate[[1]])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[3], theta=-pi/4)
state.gate[[1]] = move.Move(state.gate[[2]])
state.gate[[2]] = move.Move(state.gate[[0]])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[3], theta=pi/4)
state = move.LocalRz(atom_state=state,phi=pi/4,indices=[1])
state = local_H(atom_state=state, indices=[1])

state.gate[[0]] = move.Move(state.gate[[2]])
state = move.GlobalCZ(atom_state=state)
state = move.LocalRz(atom_state=state,phi=pi/4,indices=[0])
state = local_RX(atom_state=state, indices=[1], theta=-pi/4)
state = move.GlobalCZ(atom_state=state)
state = local_H(atom_state=state, indices=[1])

move.Execute(state)

with open('./qasm/1.2.qasm', 'r') as file:
file_content = file.read()
aggressive.Fold(move.vmove)(ans1_2)
analysis = MoveScorer(ans1_2, expected_qasm=file_content)
score = analysis.score()
for key,val in score.items():
print(f"{key}: {val}")
43 changes: 43 additions & 0 deletions team-solutions/Duckbergs/2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from bloqade import move
from iquhack_scoring import MoveScorer
import matplotlib.pyplot as plt
from kirin.passes import aggressive
from numpy import pi
from util import *

@move.vmove()
def ans2():
# Prepare
q = move.NewQubitRegister(3)
state = move.Init(
qubits=[q[0], q[1], q[2]],
indices=[2, 12, 11],
)
state.gate[[1, 4, 5]] = move.Move(state.storage[[2, 11, 12]])
state = local_RX(state, [4], pi/4)
state = move.GlobalCZ(atom_state=state)
state = local_RX(state, [4], -pi/4)
state = move.GlobalCZ(atom_state=state)
state.gate[[2,3]] = move.Move(state.gate[[1,4]])

state = local_RX(state, [3], pi/8)
state = move.GlobalCZ(atom_state=state)
state = local_RX(state, [3], -pi/8)
state = move.GlobalCZ(atom_state=state)

state.gate[[4]] = move.Move(state.gate[[2]])
state = local_RX(state, [5], pi/4)
state = move.GlobalCZ(atom_state=state)
state = local_RX(state, [5], -pi/4)
state = move.GlobalCZ(atom_state=state)
state = global_H(state)

move.Execute(state)

with open('./qasm/2.qasm', 'r') as file:
file_content = file.read()
aggressive.Fold(move.vmove)(ans2)
analysis = MoveScorer(ans2, expected_qasm=file_content)
score = analysis.score()
for key,val in score.items():
print(f"{key}: {val}")
118 changes: 118 additions & 0 deletions team-solutions/Duckbergs/3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from bloqade import move
from iquhack_scoring import MoveScorer
import matplotlib.pyplot as plt
from kirin.passes import aggressive
from numpy import pi
from util import *

alpha = [0.5550603400685824 / pi, 0.29250781484335187 / pi]
beta = [0.4877097327098487 / pi, 0.8979876956225422 / pi]


@move.vmove()
def ans3():
# Prepare
q = move.NewQubitRegister(4)
state = move.Init(
qubits=[q[0], q[1], q[2], q[3]],
indices=[0, 1, 2, 3],
)

state.gate[[0, 1, 2, 3]] = move.Move(state.storage[[0, 1, 2, 3]])
state = global_H(atom_state=state)
state = move.GlobalRz(atom_state=state, phi=beta[0] / 2)
state = move.LocalRz(atom_state=state, phi=-beta[0] / 2, indices=[0])
state = local_H(atom_state=state, indices=[2])
state = local_H(atom_state=state, indices=[3])

state.storage[[0, 1, 2, 3]] = move.Move(state.gate[[0, 1, 2, 3]])
state.gate[[0, 1]] = move.Move(state.storage[[0, 3]])
state.gate[[2, 3]] = move.Move(state.storage[[1, 2]])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[3], theta=-beta[0] / 2)
state = local_RX(atom_state=state, indices=[1], theta=-beta[0] / 2)
state = move.GlobalCZ(atom_state=state)

state.storage[[0, 1, 2]] = move.Move(state.gate[[0, 2, 3]])
state.storage[[3]] = move.Move(state.gate[[1]])
state.gate[[0, 1]] = move.Move(state.storage[[0, 2]])
state.gate[[2, 3]] = move.Move(state.storage[[1, 3]])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[1], theta=-beta[0] / 2)
state = local_RX(atom_state=state, indices=[3], theta=-beta[0] / 2)
state = move.GlobalCZ(atom_state=state)
state = global_H(atom_state=state)

state.storage[[0, 1]] = move.Move(state.gate[[0, 2]])
state.storage[[2, 3]] = move.Move(state.gate[[1, 3]])
state.gate[[0, 1, 2, 3]] = move.Move(state.storage[[0, 1, 2, 3]])
state = local_H(atom_state=state, indices=[0])
state = move.LocalRz(atom_state=state, phi=beta[0] / 2, indices=[2])
state = move.LocalRz(atom_state=state, phi=beta[0], indices=[3])
state = local_H(atom_state=state, indices=[3])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[1], theta=-beta[0] / 2)
state = local_RX(atom_state=state, indices=[3], theta=-beta[0] / 2)
state = move.GlobalCZ(atom_state=state)
state = local_H(atom_state=state, indices=[1])
state = local_H(atom_state=state, indices=[3])

state = local_RX(atom_state=state, indices=[0], theta=alpha[0])
state = local_RX(atom_state=state, indices=[1], theta=alpha[0])
state = local_RX(atom_state=state, indices=[2], theta=alpha[0])
state = local_RX(atom_state=state, indices=[3], theta=alpha[0])

# repeat
state = global_H(atom_state=state)
state = move.GlobalRz(atom_state=state, phi=beta[1] / 2)
state = move.LocalRz(atom_state=state, phi=-beta[1] / 2, indices=[0])
state = local_H(atom_state=state, indices=[2])
state = local_H(atom_state=state, indices=[3])

state.storage[[0, 1, 2, 3]] = move.Move(state.gate[[0, 1, 2, 3]])
state.gate[[0, 1]] = move.Move(state.storage[[0, 3]])
state.gate[[2, 3]] = move.Move(state.storage[[1, 2]])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[3], theta=-beta[1] / 2)
state = local_RX(atom_state=state, indices=[1], theta=-beta[1] / 2)
state = move.GlobalCZ(atom_state=state)

state.storage[[0, 1, 2]] = move.Move(state.gate[[0, 2, 3]])
state.storage[[3]] = move.Move(state.gate[[1]])
state.gate[[0, 1]] = move.Move(state.storage[[0, 2]])
state.gate[[2, 3]] = move.Move(state.storage[[1, 3]])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[1], theta=-beta[1] / 2)
state = local_RX(atom_state=state, indices=[3], theta=-beta[1] / 2)
state = move.GlobalCZ(atom_state=state)
state = global_H(atom_state=state)

state.storage[[0, 1]] = move.Move(state.gate[[0, 2]])
state.storage[[2, 3]] = move.Move(state.gate[[1, 3]])
state.gate[[0, 1, 2, 3]] = move.Move(state.storage[[0, 1, 2, 3]])
state = local_H(atom_state=state, indices=[0])
state = move.LocalRz(atom_state=state, phi=beta[1] / 2, indices=[2])
state = move.LocalRz(atom_state=state, phi=beta[1], indices=[3])
state = local_H(atom_state=state, indices=[3])
state = move.GlobalCZ(atom_state=state)
state = local_RX(atom_state=state, indices=[1], theta=-beta[1] / 2)
state = local_RX(atom_state=state, indices=[3], theta=-beta[1] / 2)
state = move.GlobalCZ(atom_state=state)
state = local_H(atom_state=state, indices=[1])
state = local_H(atom_state=state, indices=[3])

state = local_RX(atom_state=state, indices=[0], theta=alpha[1])
state = local_RX(atom_state=state, indices=[1], theta=alpha[1])
state = local_RX(atom_state=state, indices=[2], theta=alpha[1])
state = local_RX(atom_state=state, indices=[3], theta=alpha[1])

move.Execute(state)


with open("./qasm/3.qasm", "r") as file:
file_content = file.read()
aggressive.Fold(move.vmove)(ans3)
analysis = MoveScorer(ans3, expected_qasm=file_content)
score = analysis.score()
for key, val in score.items():
print(f"{key}: {val}")
41 changes: 41 additions & 0 deletions team-solutions/Duckbergs/4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from bloqade import move
from iquhack_scoring import MoveScorer
import matplotlib.pyplot as plt
from kirin.passes import aggressive
from numpy import pi
from util import *

@move.vmove()
def ans4():
# Prepare
q = move.NewQubitRegister(9)
state = move.Init(
qubits=[q[0], q[1], q[2], q[3], q[4], q[5], q[6], q[7], q[8]],
indices=[15, 17, 18, 14, 4, 5, 16, 24, 25],
)
state = global_H(state)
state.gate[[2, 3]] = move.Move(state.storage[[14, 15]])
state = local_H(state, [3])
state = move.GlobalCZ(atom_state=state)
state.gate[[1]] = move.Move(state.gate[[2]])
state.gate[[0, 2]] = move.Move(state.storage[[4,16]])
state = move.GlobalCZ(atom_state=state)
state = local_H(state, [3])
state.storage[[3]] = move.Move(state.gate[[0]])
state.gate[[4]] = move.Move(state.gate[[2]])
state.gate[[2, 5]] = move.Move(state.storage[[17, 24]])
state = move.GlobalCZ(atom_state=state)
state.storage[[17, 24]] = move.Move(state.gate[[2, 5]])
state.gate[[0, 2, 5]] = move.Move(state.storage[[5, 18, 25]])
state = move.GlobalCZ(atom_state=state)
state = global_H(state)
state = local_H(state, [1, 3, 4])
move.Execute(state)

with open('./qasm/4.qasm', 'r') as file:
file_content = file.read()
aggressive.Fold(move.vmove)(ans4)
analysis = MoveScorer(ans4, expected_qasm=file_content)
score = analysis.score()
for key,val in score.items():
print(f"{key}: {val}")
41 changes: 41 additions & 0 deletions team-solutions/Duckbergs/5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from bloqade import move
from iquhack_scoring import MoveScorer
import matplotlib.pyplot as plt
from kirin.passes import aggressive
from numpy import pi
from util import *

@move.vmove()
def ans5():
# Prepare
q = move.NewQubitRegister(7)
state = move.Init(
qubits=[q[0], q[1], q[2], q[3], q[4], q[5], q[6]],
indices=[1,2, 11, 18, 12, 16,17 ],
)
state = global_H(state)
state.gate[[0,1, 4,5, 6,7]] = move.Move(state.storage[[1,2, 11,12, 16,17]])
state = local_H(state, [7])
state = move.GlobalCZ(atom_state=state)
state.gate[[2,3, 4]] = move.Move(state.gate[[0, 4, 7]])
state.gate[[7]] = move.Move(state.storage[[18]])
state = move.GlobalCZ(atom_state=state)
state = local_H(state, [4])
state.gate[[0,2,4]] = move.Move(state.gate[[2,4,7]])
state.gate[[7]] = move.Move(state.gate[[1]])
state = move.GlobalCZ(atom_state=state)
state.gate[[1,8]] = move.Move(state.gate[[4,6]])
state.gate[[6]] = move.Move(state.gate[[2]])
state = move.GlobalCZ(atom_state=state)
state = global_H(state)
state = local_H(state, [1, 3, 7])

move.Execute(state)

with open('./qasm/5.qasm', 'r') as file:
file_content = file.read()
aggressive.Fold(move.vmove)(ans5)
analysis = MoveScorer(ans5, expected_qasm=file_content)
score = analysis.score()
for key,val in score.items():
print(f"{key}: {val}")
38 changes: 38 additions & 0 deletions team-solutions/Duckbergs/FileDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Additional Files

This section provides an overview of the key additional files used in this project.

## **genetic_algorithm.py**

This module implements a **Genetic Algorithm (GA)** for optimizing quantum gate scheduling. The algorithm generates an initial population of gate schedules, evaluates their fitness based on cost metrics, and evolves the schedules through selection, crossover, and mutation to find an optimal solution.

### **Key Features:**

- **Heuristic-based Scheduling**: Uses movement and adjacency heuristics for efficient scheduling.
- **Cost Evaluation**: Assigns scores based on gate execution time, qubit movement, and entanglement constraints.
- **Mutation and Crossover**: Introduces genetic variations to explore better solutions.
- **Multi-Generation Evolution**: Iterates through multiple generations to refine scheduling.

### **Dependencies:**

- NumPy for numerical operations
- Matplotlib for visualization
- Custom heuristics and movement strategies

---

## **valid_move_generator.py**

This module is responsible for **generating valid movement schedules** for neutral atom quantum computing architectures. It ensures qubits are moved efficiently between storage and gate zones while maintaining hardware constraints.

### **Key Features:**

- **Movement Cost Calculation**: Computes time required to transfer qubits between different zones.
- **Gate Adjacency Constraints**: Ensures qubits are placed optimally for entangling operations.
- **QASM Parsing Support**: Extracts gate operations from OpenQASM circuits to guide movement.
- **Integration with Genetic Algorithm**: Provides movement cost matrices for optimization.

### **Dependencies:**

- NumPy for movement calculations
- Custom adjacency heuristics for scheduling
Binary file added team-solutions/Duckbergs/Presentation.pdf
Binary file not shown.
Loading