GithubHelp home page GithubHelp logo

Matrix of S Gate about quantum-circuit HOT 5 CLOSED

quantastica avatar quantastica commented on August 16, 2024
Matrix of S Gate

from quantum-circuit.

Comments (5)

glanzz avatar glanzz commented on August 16, 2024

Looks like 'mathjs' evaluates to different values when used exp(i*pi/2) and i where the first adds some real part to the apart from the imaginary part.

const math = require('mathjs')
console.log(math.evaluate("i"))
console.log(math.evaluate("exp(i * pi / 2)"))
Complex { re: 0, im: 1 }
Complex { re: 6.123233995736766e-17, im: 1 }

from quantum-circuit.

perak avatar perak commented on August 16, 2024

@glanzz thank you for reporting, but I claim this is not a bug.

Error on 16th decimal place simply cannot make that big difference in results.

You have too small number of shots. If I run your example multiple times, I get very different counts each time, which is normal behavior:

{ '0': 50, '1': 50 }
{ '0': 49, '1': 51 }

{ '0': 41, '1': 59 }
{ '0': 60, '1': 40 }

{ '0': 49, '1': 51 }
{ '0': 39, '1': 61 }

{ '0': 59, '1': 41 }
{ '0': 49, '1': 51 }

Try with more shots:

{ '0': 5017, '1': 4983 }
{ '0': 5037, '1': 4963 }

{ '0': 4980, '1': 5020 }
{ '0': 4965, '1': 5035 }

{ '0': 5054, '1': 4946 }
{ '0': 5009, '1': 4991 }

By the way, there is: circuit.measureAllMultishot(numShots) method which simplifies code:

import QuantumCircuit from 'quantum-circuit';


var ss = new QuantumCircuit();
ss.addGate("h", 0,0) // Apply this so that imaginary part is accounted
ss.addGate("s", 1,0)
ss.addGate("s", 2,0)


var z = new QuantumCircuit();
z.addGate("h", 0,0) // Apply this so that imaginary part is accounted
z.addGate("z", 1, 0)

const shots = 100;
for(let circuit of [ss, z]) {
  circuit.run([true]);
  results = circuit.measureAllMultishot(shots);
  console.log(results)
}

P.S. if you try the same with Qiskit or other framework (also with real quantum computer), you will get similar results.

from quantum-circuit.

perak avatar perak commented on August 16, 2024

I mean, this is a bug (in mathjs), but effect on results is insignificant.

from quantum-circuit.

perak avatar perak commented on August 16, 2024

Ah, now I see what you are suggesting: simple solution to decimal error in this case is to simply change matrix definition from exp(i * pi / 2) to i. Will be done in the next update šŸ‘ Thanks.

(but this will not change results in your example code - results are already correct)

from quantum-circuit.

perak avatar perak commented on August 16, 2024

Fixed in v.0.9.223:

  • Matrices of S and Controlled-S are changed from exp(i * pi / 2) to i.
  • Matrices of Sā€  and Controlled-Sā€  are changed from exp(-i * pi / 2) to -i.

Thank you @glanzz

from quantum-circuit.

Related Issues (20)

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.