Coder Social home page Coder Social logo

qsharp-integrations's People

Contributors

ahelwer avatar amirebrahimi avatar anpaz avatar bartdesmet avatar cgranade avatar cpalmer2020 avatar crazy4pi314 avatar eginez avatar guanghaolow avatar jond01 avatar lemj3111 avatar martinquantum avatar mlxd avatar msoeken avatar rolfhuisman avatar russell-taylor avatar shahakl avatar tamamcglinn avatar tcnickolas avatar thomashaener avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

qsharp-integrations's Issues

U gate parsing from QASM to Q# is wrong

The following QASM code

OPENQASM 2.0;
qreg q[1];
U(θ,φ,λ) q[0];

is translated to this Q# code (not complete):

use q = Qubit[1] {
    Rx(θ, q[0]);
    Ry(φ, q[0]);
    Rz(λ, q[0]);
    ResetAll(q);
}

This logic is implemented in the following parts of Parser.cs:

case "U":
case "u3":
ParseUGate(token, inside);
break;

private static void ParseUGate(IEnumerator<string> token, StringBuilder builder)
{
token.MoveNext(); //(
token.MoveNext();
var x = ParseCalculation(token, COMMA, CLOSE_PARENTHESES);
token.MoveNext();
var y = ParseCalculation(token, COMMA, CLOSE_PARENTHESES);
token.MoveNext();
var z = ParseCalculation(token, COMMA, CLOSE_PARENTHESES);
token.MoveNext();
var q = token.Current;
token.MoveNext(); // ;
bool written = false;
if (!x.Equals(ZERO))
{
written = true;
Indent(builder);
builder.AppendFormat("Rx({0}, {1});\n", x, q);
}
if (!y.Equals(ZERO))
{
written = true;
Indent(builder);
builder.AppendFormat("Ry({0}, {1});\n", y, q);
}
if (!z.Equals(ZERO))
{
written = true;
Indent(builder);
builder.AppendFormat("Rz({0}, {1});\n", z, q);
}
if (!written)
{
// 0,0,0 rotation is the idle
// Could have left it out, but people seem to use this as a first test and are surprised when it gets optimized away.
Indent(builder);
builder.AppendFormat("I({0});\n", q);
}
}

However, the definition of QASM's U gate is:
image

And the above is not equal to Rz(λ)*Ry(φ)*Rx(θ).
See the following gist for more details:
https://gist.github.com/jond01/c942a7358e27e99aa6a68ea7ef42fe65

The correct translation is:
U(θ, φ, λ) = e^{i(φ+λ)/2}*Rz(φ)*Ry(θ)*Rz(λ)
(See Eqs. (1) and (2) in https://arxiv.org/pdf/2104.14722.pdf#page=11.)

It is essential to fix ParseUGate code and would be nice to implement a Q# operation U that contains the rotations and the global phase.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.