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

Add Deutsch-Jozsa algorithm example #36

Merged
merged 3 commits into from
Oct 24, 2021

Conversation

oxarbitrage
Copy link
Contributor

I was learning about the Deutsch-Jozsa so i wrote some code for a demo. Feel free to:

  • suggest changes, i will try to make them when i have time.
  • make changes directly.
  • merge.
  • not merge.
  • etc.

@oxarbitrage oxarbitrage changed the title Add Deutsch-Jozsa algorithm algorithm example Add Deutsch-Jozsa algorithm example Oct 19, 2021
@Renmusxd
Copy link
Owner

So there's a simplified version of Deutsch in examples already, but this one seems like a mapping from the qiskit link you provided, is that true?
If so I don't mind adding that for a display of variety.

let measured = measurements.get_measurement(&m).unwrap();

assert_eq!(measured.0, output as u64);
assert_eq!(measured.1, 1.0);
Copy link
Owner

Choose a reason for hiding this comment

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

should use some sort of almost_eq

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why ?

let (_, measurements) = run_local::<f64>(&r).unwrap();
let measured = measurements.get_measurement(&m).unwrap();

if measured.1 > 0.99 && measured.0 == 0 {
Copy link
Owner

Choose a reason for hiding this comment

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

Use 1.0 - f64::epsilon rather than 0.99 if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok(())
}

#[derive(Clone, Debug)]
Copy link
Owner

Choose a reason for hiding this comment

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

Can add Copy to remove .clone() call later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oxarbitrage
Copy link
Contributor Author

So there's a simplified version of Deutsch in examples already, but this one seems like a mapping from the qiskit link you provided, is that true?

Yes, it seems several textbooks/courses treat the Deutsch algorithm and the general version called Deutsch-Jozsa as different algorithms and that makes sense to me for a few reasons:

  • Deutsch-Jozsa was discovered later in time than the special case Deutsch.
  • Deutsch-Jozsa can handle bit string inputs of arbitrary size while Deutsch only can handle inputs of a 1 and/or a 0.

Technically they are very similar but as you said, for variety i think it will be good to have this one.

@Renmusxd Renmusxd merged commit 54d8e64 into Renmusxd:master Oct 24, 2021
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.

2 participants