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

Feat/rotation_z gate #362

Merged
merged 8 commits into from
Jan 31, 2024
Merged

Feat/rotation_z gate #362

merged 8 commits into from
Jan 31, 2024

Conversation

fSosaRey
Copy link
Collaborator

No description provided.

@fSosaRey fSosaRey self-assigned this Jan 30, 2024
@fSosaRey fSosaRey changed the base branch from main to fix/global-phase January 30, 2024 16:05
@@ -1838,5 +1838,5 @@ function compare_operators(H_0::AbstractOperator, H_1::AbstractOperator)::Bool
δ = get_canonical_global_phase(m_0) - get_canonical_global_phase(m_1)

# We need to check atol for values close to zero
return isapprox(m_0, exp(im * δ) .* m_1; atol = sqrt(eps(typeof(δ))))
return isapprox(m_0, exp(im * δ) .* m_1; atol = 1e-6)
Copy link
Collaborator Author

@fSosaRey fSosaRey Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this because between rotation_z and it's universal equivalent there was an error 20% above sqrt(eps()), 1.4e-8 vs 1.2e-8, making the tests fail

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be fixed by also specifying the rtol instead of increasing the atol? According to the Julia documentation, rtol is zeroed instead of being sqrt(eps(typeof(\delta))), which is not what I originally intended.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following is the failing test case. I tried using rtol instead of atol but it also needs to be raised to at least 2*sqrt(eps(typeof(delta)).

using Snowflurry
using Test

target = 1
theta = pi / 5

instr = rotation_z(target, theta)

universal_equivalent =
    Snowflurry.as_universal_gate(target, get_operator(get_gate_symbol(instr)))

alpha = Snowflurry.get_canonical_global_phase(get_matrix(get_operator(get_gate_symbol(instr))))

println("alpha: $alpha")

println("instr: $(exp(im*-alpha) * get_operator(get_gate_symbol(instr)))")
println("universal: $(get_operator(get_gate_symbol(universal_equivalent)))")

@test Snowflurry.compare_operators(
            get_operator(get_gate_symbol(instr)),
            get_operator(get_gate_symbol(universal_equivalent)),
        )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we are compounding errors, and then the tolerances stop making sense. For now, we should leave it as is. I've created a very-low-priority issue to allow specifying the tolerances of compare functions here.

Copy link

codecov bot commented Jan 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (11a7245) 100.00% compared to head (d7360c2) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #362   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2467      2471    +4     
=========================================
+ Hits          2467      2471    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -1838,5 +1838,5 @@ function compare_operators(H_0::AbstractOperator, H_1::AbstractOperator)::Bool
δ = get_canonical_global_phase(m_0) - get_canonical_global_phase(m_1)

# We need to check atol for values close to zero
return isapprox(m_0, exp(im * δ) .* m_1; atol = sqrt(eps(typeof(δ))))
return isapprox(m_0, exp(im * δ) .* m_1; atol = 1e-6)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be fixed by also specifying the rtol instead of increasing the atol? According to the Julia documentation, rtol is zeroed instead of being sqrt(eps(typeof(\delta))), which is not what I originally intended.

"""
rotation_z(target, lambda)

Return a `Gate` that applies a symmetric phase shift of `-lambda/2` and `+lambda/2` to the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See discussion on #361 regarding "symmetric phase shift".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to a more standard docstring

Base automatically changed from fix/global-phase to main January 31, 2024 16:18
@plerouxanyon plerouxanyon merged commit 2546c4f into main Jan 31, 2024
20 checks passed
@plerouxanyon plerouxanyon deleted the feat/RotationZ-gate branch January 31, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants