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

Merge Development #57

Merged
merged 17 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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: 3 additions & 3 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Qutes Build and Tests

on:
push:
branches: [ "main" ]
branches: [ "main", "development" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "development" ]

permissions:
contents: read
Expand All @@ -29,6 +29,6 @@ jobs:
- name: Test with pytest
run: |
cd src
python -m pytest tests/
python -m pytest tests/ # Better CLI output than unittest
# python -m unittest discover -s ./test -p 'test*.py'
# python -m unittest tests.grammar_test
27 changes: 27 additions & 0 deletions playground/examples/grover_search.qut
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// qustring a = "0*00";

qustring c = "00000011";
if("1" is c){
print "Exact Match Found!";
}
else{
print "Exact Match Not Found";
}



// quint a = [0q, 0q, 0q, 0q, 0q, 0q, [0,1]q, [0,1]q];
// qustring b = "1110111";
// if("11" is a){
// print "Exact Match Found!";
// }
// else{
// print "Exact Match Not Found";
// }

// if("01" in b){
// print "Substring Match Found!";
// }
// else{
// print "Substring Match Not Found";
// }
212 changes: 212 additions & 0 deletions playground/examples/quantum_key_distribution_bb84.qut
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
int n = 8; //number of qubits

//Alice create a random binary sequence
string message_0 = "1";
string message_1 = "0";
string message_2 = "1";
string message_3 = "0";
string message_4 = "0";
string message_5 = "1";
string message_6 = "0";
string message_7 = "1";

//Alice create a random binary sequence of basis
string alice_bases0 = "1";
string alice_bases1 = "1";
string alice_bases2 = "0";
string alice_bases3 = "0";
string alice_bases4 = "0";
string alice_bases5 = "1";
string alice_bases6 = "1";
string alice_bases7 = "1";

//Alice encodes the message with the basis
//for each character in message, if the corresponding character in bases is 0, then encode the character in Z basis, otherwise in X basis
qubit alice_0 = 1q;
qubit alice_1 = 0q;
qubit alice_2 = 1q;
qubit alice_3 = 0q;
qubit alice_4 = 0q;
qubit alice_5 = 1q;
qubit alice_6 = 0q;
qubit alice_7 = 1q;

//Bob create a random binary sequence of basis
string bob_bases0 = "1";
string bob_bases1 = "0";
string bob_bases2 = "1";
string bob_bases3 = "0";
string bob_bases4 = "1";
string bob_bases5 = "0";
string bob_bases6 = "1";
string bob_bases7 = "0";


if (alice_bases0 == "0"){
//encode message_1 in Z basis
//do nothing.
} else {
//encode message_0 in X basis
hadamard alice_0;
}
if (alice_bases1 == "0"){
//encode message_1 in Z basis
//do nothing.
} else {
//encode message_1 in X basis
hadamard alice_1;
}
if (alice_bases2 == "0"){
//encode message_2 in Z basis
//do nothing.
} else {
//encode message_2 in X basis
hadamard alice_2;
}
if (alice_bases3 == "0"){
//encode message_3 in Z basis
//do nothing.
} else {
//encode message_3 in X basis
hadamard alice_3;
}
if (alice_bases4 == "0"){
//encode message_4 in Z basis
//do nothing.
} else {
//encode message_4 in X basis
hadamard alice_4;
}
if (alice_bases5 == "0"){
//encode message_5 in Z basis
//do nothing.
} else {
//encode message_5 in X basis
hadamard alice_5;
}
if (alice_bases6 == "0"){
//encode message_6 in Z basis
//do nothing.
} else {
//encode message_6 in X basis
hadamard alice_6;
}
if (alice_bases7 == "0"){
//encode message_7 in Z basis
//do nothing.
} else {
//encode message_7 in X basis
hadamard alice_7;
}


//Alice sends the encoded message to Bob





if (bob_bases0 == "0"){
//encode message_1 in Z basis
//do nothing.
} else {
//encode message_0 in X basis
hadamard alice_0;
}

if (bob_bases1 == "0"){
//encode message_1 in Z basis
//do nothing.
} else {
//encode message_1 in X basis
hadamard alice_1;
}
if (bob_bases2 == "0"){
//encode message_2 in Z basis
//do nothing.
} else {
//encode message_2 in X basis
hadamard alice_2;
}
if (bob_bases3 == "0"){
//encode message_3 in Z basis
//do nothing.
} else {
//encode message_3 in X basis
hadamard alice_3;
}
if (bob_bases4 == "0"){
//encode message_4 in Z basis
//do nothing.
} else {
//encode message_4 in X basis
hadamard alice_4;
}
if (bob_bases5 == "0"){
//encode message_5 in Z basis
//do nothing.
} else {
//encode message_5 in X basis
hadamard alice_5;
}
if (bob_bases6 == "0"){
//encode message_6 in Z basis
//do nothing.
} else {
//encode message_6 in X basis
hadamard alice_6;
}
if (bob_bases7 == "0"){
//encode message_7 in Z basis
//do nothing.
} else {
//encode message_7 in X basis
hadamard alice_7;
}





if(bob_bases0 == alice_bases0){
print "Index 0 match so it can be used to create a key";
print alice_0;
print message_0;
}
if(bob_bases1 == alice_bases1){
print "Index 1 match so it can be used to create a key";
print alice_1;
print message_1;
}
if(bob_bases2 == alice_bases2){
print "Index 2 match so it can be used to create a key";
print alice_2;
print message_2;
}
if(bob_bases3 == alice_bases3){
print "Index 3 match so it can be used to create a key";
print alice_3;
print message_3;
}
if(bob_bases4 == alice_bases4){
print "Index 4 match so it can be used to create a key";
print alice_4;
print message_4;
}
if(bob_bases5 == alice_bases5){
print "Index 5 match so it can be used to create a key";
print alice_5;
print message_5;
}
if(bob_bases6 == alice_bases6){
print "Index 6 match so it can be used to create a key";
print alice_6;
print message_6;
}
if(bob_bases7 == alice_bases7){
print "Index 7 match so it can be used to create a key";
print alice_7;
print message_7;
}

print "If the above values matches, then no one is eyesdropping.";
75 changes: 75 additions & 0 deletions playground/examples/quantum_teleportation.qut
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//qubit a = 0.7,0.3q;
qubit a = 0q;
//measure a;

qubit bell1 = 0q;
qubit bell2 = 0q;

//Provider
hadamard bell1;
mcx bell1, bell2;

//Alice
mcx a, bell1;
hadamard a;
// measure a;
// measure bell1;

//Bob
bool do_z = a;
bool do_x = bell1;
if(do_x){
not bell2;
}
if(do_z){
pauliz bell2;
}

measure bell2;


print "Initial Message:";
print a;
print "Teleported Message:";
print bell2;



//TODO: There is some error when multiple functions are declared
// qubit aliceMessage = 0q;

// qubit bell1 = 0q;
// qubit bell2 = 0q;

// initBellPairs(bell1, bell2);

// //Alice
// aliceEncoding(bell1);

// //Bob
// bool do_z = aliceMessage;
// bool do_x = bell1;
// bobDecoding(do_z, do_x);



// void initBellPairs(qubit a, qubit b){
// hadamard a;
// mcx a, b;
// }

// void aliceEncoding(qubit alice_bell){
// mcx aliceMessage, alice_bell;
// hadamard aliceMessage;
// }

// void bobDecoding(bool do_z, bool do_x){
// if(do_x){
// not bell2;
// }
// if(do_z){
// pauliz bell2;
// }

// measure bell2;
// }
44 changes: 44 additions & 0 deletions playground/examples/superdense_coding.qut
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//Provider
qubit bell1;
qubit bell2;

hadamard bell2;
mcx bell2, bell1;
// - Send bell2 to Alice and Bell1 to Bob

//Alice
qustring qu_message = "**";
string message = qu_message;

if(message == "00"){
//do nothing
}
else if(message == "01"){
pauliz bell2;
}
else if(message == "10"){
not bell2;
}
else if(message == "11"){
pauliz bell2;
not bell2;
}

// - Send transformed bell2 to Bob


//Bob
mcx bell2, bell1;
hadamard bell2;


bool received_bit1 = bell1;
bool received_bit2 = bell2;

print "Messaggio Inviato: ";
print message;
print "Messaggio Ricevuto: ";
//TODO: Here we print always the first message because the circuit is created upon that.
// We should run Qutes 'runs' times or create the circuit with Qiskit if statements upon classical registers.
print received_bit1;
print received_bit2;
4 changes: 4 additions & 0 deletions playground/examples/test.qut
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
qubit a = 0q;
bool b = a;

print b;
Loading
Loading