-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/commutation check #12
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
93fefbc
ee1c241
96b8821
a7f9d36
f4ade66
b2e9180
00f7e90
232a5ad
6f28443
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ scratch/ | |
| .history | ||
| .vscode | ||
| *.png | ||
| dev.jl | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """ | ||
| This file contains the main iteration structures and functions for the PBCCompiler. | ||
| It defines how to propagate Pauli Product Measurements (PPMs) through a quantum circuit | ||
| Provides functions to handle commute condition and anticommute condition | ||
| Provides functions to handle PBC List update and Check list update | ||
| """ | ||
|
|
||
|
|
||
| using PBCCompiler | ||
| using PBCCompiler: Circuit, CircuitOp, Measurement, ExpHalfPiPauli, ExpQuatPiPauli, ExpEighPiPauli, PauliConditional, BitConditional, affectedqubits | ||
| using QuantumClifford: comm, embed | ||
| using Moshi.Match: @match | ||
|
|
||
|
|
||
| function affectedpaulis(op::CircuitOp.Type) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a docstring to the function that explains what it is and what it is for. Use |
||
| qubits = @match op begin | ||
| CircuitOp.Pauli(pauli, qubits) => pauli | ||
| CircuitOp.Measurement(pauli, bit, qubits) => pauli | ||
| CircuitOp.ExpHalfPiPauli(pauli, qubits) => pauli | ||
| CircuitOp.ExpQuatPiPauli(pauli, qubits) => pauli | ||
| CircuitOp.ExpEighPiPauli(pauli, qubits) => pauli | ||
| CircuitOp.PauliConditional(cp, cq, tp, tq) => vcat(cp, tp) | ||
| end | ||
| end | ||
|
|
||
| function complete_paulis(op1::CircuitOp.Type, op2::CircuitOp.Type) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring, as mentioned for the previous one. Check the julia documentation on how to structure docstrings. |
||
| pu1=affectedpaulis(op1) | ||
| pu2=affectedpaulis(op2) | ||
| println("Affected Paulis of op1: ", pu1) | ||
|
||
| println("Affected Paulis of op2: ", pu2) | ||
| qu1=affectedqubits(op1) | ||
| qu2=affectedqubits(op2) | ||
| println("Affected qubits of op1: ", qu1) | ||
| println("Affected qubits of op2: ", qu2) | ||
| AffectedQubbits=sort(union(qu1,qu2)) | ||
| println("Affected qubits of both ops: ", AffectedQubbits) | ||
| Paulilen=maximum(AffectedQubbits) | ||
| println("Length of the affected Pauli string: ", Paulilen) | ||
| Pauli1=embed(Paulilen, qu1, pu1) | ||
| Pauli2=embed(Paulilen, qu2, pu2) | ||
| println("New Pauli string of op1: ", Pauli1) | ||
| println("New Pauli string of op2: ", Pauli2) | ||
| return (Pauli1, Pauli2) | ||
| end | ||
|
|
||
| function check_commutation(op1::CircuitOp.Type, op2::CircuitOp.Type) | ||
|
|
||
| @match (op1, op2) begin | ||
| #scenario 1: One of them is classical controlled gate | ||
| (op,CircuitOp.BitConditional(inner_op, bit)) || (CircuitOp.BitConditional(inner_op, bit), op) => begin | ||
| println("Invalid input: Need to determine gate present first") | ||
| end | ||
| #scenario 2: One of them is Pauli Conditional gate | ||
| (op, CircuitOp.PauliConditional(cp, cq, tp, tq)) || (CircuitOp.PauliConditional(cp, cq, tp, tq), op) => begin | ||
| println("One of the operations is a Pauli conditional gate. ") | ||
| cop=ExpQuatPiPauli(cp, cq) | ||
| top=ExpQuatPiPauli(tp, tq) | ||
| comm_cop=check_commutation(op, cop) | ||
| comm_top=check_commutation(op, top) | ||
| if comm_cop == 0 && comm_top == 0 | ||
| println("The operation commutes with both the control and target Paulis of the conditional gate.") | ||
| elseif comm_cop != 0 && comm_top != 0 | ||
| println("The operation anticommutes with both the control and target Paulis of the conditional gate.") | ||
| else | ||
| println("The operation commutes with one of the control and target Paulis of the conditional gate, and anticommutes with the other.") | ||
| end | ||
| return (comm_cop, comm_top) | ||
| end | ||
| #scenario 3: Both are Pauli Product Rotations | ||
| _ => begin | ||
| (Pauli1,Pauli2)=complete_paulis(op1, op2) | ||
| commutativity=comm(Pauli1,Pauli2) | ||
| if commutativity == 0 | ||
| println("The two operations commute.") | ||
| else | ||
| println("The two operations anticommute.") | ||
| end | ||
| return commutativity | ||
| end | ||
| #scenario 2: one is a Controlled gate | ||
|
|
||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| module PBCCompiler | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not edit unrelated parts of the files, it makes the diffs noisy and more difficult to review |
||
| using Moshi.Data: @data | ||
| using Moshi.Match: @match | ||
| using QuantumClifford: PauliOperator, @P_str | ||
|
|
@@ -64,6 +63,7 @@ using .CircuitOp: Measurement, Pauli, ExpHalfPiPauli, ExpQuatPiPauli, ExpEighPiP | |
| include("traversal.jl") | ||
| include("affectedqubits.jl") | ||
| include("plotting.jl") | ||
| include("MainIteration.jl") | ||
|
|
||
| ## | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| @testitem "check_commutation" tags=[:check_commutation] begin | ||
|
|
||
| using PBCCompiler | ||
| using PBCCompiler: Circuit, CircuitOp, Measurement, ExpHalfPiPauli, ExpQuatPiPauli, ExpEighPiPauli, PauliConditional, BitConditional, affectedqubits | ||
| using Test | ||
| using PBCCompiler: check_commutation | ||
| using QuantumClifford: @P_str, comm | ||
| @testset "Test unordered input" begin | ||
| op1=ExpQuatPiPauli(P"XY", [1, 3]) | ||
| op2=ExpQuatPiPauli(P"ZXY", [3, 1, 2]) | ||
|
|
||
| t_1=comm(op1.pauli,op2.pauli) | ||
| @test t_1 == 0x00 | ||
|
|
||
| t_2=check_commutation(op1, op2) | ||
| @test t_2 == 0x01 | ||
|
|
||
| end | ||
|
|
||
| @testset "Test non-overlapping input" begin | ||
| op1=ExpQuatPiPauli(P"X", [1]) | ||
| op2=ExpQuatPiPauli(P"Z", [2]) | ||
|
|
||
| t_1=comm(op1.pauli,op2.pauli) | ||
| @test t_1 == 0x01 | ||
|
|
||
| t_2=check_commutation(op1, op2) | ||
| @test t_2 == 0x00 | ||
|
|
||
| end | ||
|
|
||
| @testset "Test partially overlapping input" begin | ||
| op1=ExpQuatPiPauli(P"XX", [1, 3]) | ||
| op2=ExpQuatPiPauli(P"ZY", [3, 4]) | ||
|
|
||
| t_1=comm(op1.pauli,op2.pauli) | ||
| @test t_1 == 0x00 | ||
|
|
||
| t_2=check_commutation(op1, op2) | ||
| @test t_2 == 0x01 | ||
|
|
||
| end | ||
|
|
||
| @testset "Test different Pauli Product Rotation input" begin | ||
| op1=ExpHalfPiPauli(P"X", [1]) | ||
| op2=ExpQuatPiPauli(P"Z", [1]) | ||
| op3=ExpEighPiPauli(P"Y", [1]) | ||
|
|
||
| t_1=check_commutation(op1,op2) | ||
| @test t_1 == 0x01 | ||
|
|
||
| t_2=check_commutation(op1, op2) | ||
| @test t_2 == 0x01 | ||
|
|
||
| t_3=check_commutation(op1,op3) | ||
| @test t_3 == 0x01 | ||
|
|
||
| end | ||
|
|
||
| @testset "Test Pauli Conditional input" begin | ||
| op1=ExpQuatPiPauli(P"ZX", [1, 2]) | ||
| op2=ExpQuatPiPauli(P"ZY", [1, 2]) | ||
| op3=ExpQuatPiPauli(P"YX", [1, 2]) | ||
| CNOT=PauliConditional(P"Z", [1], P"X", [2]) | ||
|
|
||
| t_1=check_commutation(op1,CNOT) | ||
| @test t_1 == (0x00,0x00) | ||
|
|
||
| t_2=check_commutation(op2,CNOT) | ||
| @test t_2 == (0x00,0x01) | ||
|
|
||
| t_3=check_commutation(op3,CNOT) | ||
| @test t_3 == (0x01,0x00) | ||
|
|
||
| end | ||
|
|
||
| @testset "Test Bit Conditional input" begin | ||
| op1=ExpQuatPiPauli(P"X", [1]) | ||
| op2=ExpQuatPiPauli(P"Z", [1]) | ||
| bit_cond_op=BitConditional(op1, 0) | ||
|
|
||
| t_1=check_commutation(bit_cond_op, op2) | ||
| @test t_1 === nothing | ||
|
|
||
| end | ||
|
|
||
| end | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice the warning about a missing new line at the end of this file. Set your editor to clean these things automatically. Here is the settings I have added to vscode for instance: Some of these might be redundant -- they have grown organically. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "underdeveloped" mean? Unfinished or unreleased?
If it is "unfinished", let's just make sure we finish them in a well structured PR. If it is "unreleased", then put them with the rest in v0.1.0-dev which is also unreleased.