-
Notifications
You must be signed in to change notification settings - Fork 18
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
Examples PR 1: dense_coding, bell_inequalities, cswap #41
base: master
Are you sure you want to change the base?
Conversation
The type error you are describing is because your signature looks like: fn run_alice<P: Precision, CB: CircuitBuilder>(b: &mut LocalBuilder<P>, epr_alice: CB::Register, bit_a: bool, bit_b: bool) -> CB::Register {
match (bit_a, bit_b) {
(false, false) => epr_alice,
(false, true) => b.x(epr_alice),
(true, false) => b.z(epr_alice),
(true, true) => b.y(epr_alice),
}
} So while it's taking a CB::Register for epr_alice, it's taking a LocalBuilder for the builder, it should look like: fn run_alice<P: Precision, CB: CliffordTBuilder<P>>(b: &mut CB, epr_alice: CB::Register, bit_a: bool, bit_b: bool) -> CB::Register {
match (bit_a, bit_b) {
(false, false) => epr_alice,
(false, true) => b.x(epr_alice),
(true, false) => b.z(epr_alice),
(true, true) => b.y(epr_alice),
}
} |
Or of course you could lean into the LocalBuilder and ignore the generics: fn run_alice<P: Precision>(b: &mut LocalBuilder<P>, epr_alice: Qudit, bit_a: bool, bit_b: bool) -> Qudit {
match (bit_a, bit_b) {
(false, false) => epr_alice,
(false, true) => b.x(epr_alice),
(true, false) => b.z(epr_alice),
(true, true) => b.y(epr_alice),
}
} |
Quick question, what would we use instead of the |
program! should work - it lives in qip-macro now since it's a procedural macro rather than a macro_rules! one. |
OK, got it. Will take a closer look tonight |
Feel free to share any thoughts or feedback you have so far. I wanted to ask how does this program! macro work? Initially, I got my functions undetected, and when I clicked the empty main function to run, they got detected? I generally follow a pattern as the code is a bit difficult and want to get this done quickly, why do we use |
program! Is a procedural macro, which means it is a bit of code that gets compiled before the rest then included into the compiler itself. Basically it lets the programmer make something like a custom interpreter which translates plain text into rust before everything is fed into the normal compiler. Documentation here |
That cfg thing you pointed out is a conditional compilation - basically it says "only try to compile this if the feature called 'macros' is enabled". Documentation here |
I tried to run these examples and there are a large number of compiler errors:
Also to ensure people know to run with the |
} | ||
|
||
#[cfg(not(feature = "macros"))] | ||
fn main() -> () {} |
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.
We should put an error message here telling the user to run with the macro feature or --all-features
.
for (bit_a, bit_b) in bits_a.into_iter().zip(bits_b.into_iter()) { | ||
let mut b = LocalBuilder::<f64>::default(); | ||
let epr_alice = b.register(n); | ||
let epr_bob = b.register(n); |
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.
You made a change here which broke the example:
What you implemented is two independent qubits, whereas superdense coding requires two entabled qubits (EPR pair):
See
RustQIP/examples/dense_coding.rs
Line 62 in 56757b5
let (epr_alice, epr_bob) = epr_pair(&mut b, 1); |
I dont think the library currently has an EPR function, but I can add one later. You should look up how to make an EPR pair yourself and try implementing that as a helper function for this example.
While you are still working on these I'm going to convert them to drafts, let me know once they are ready for review. |
Hi, @Renmusxd could you have a look at my Also, how can I get rid of this error |
I believe the circuit3 is doing the correct thing - the reason you're getting that error for circuit1 is because you are passing |
So I think I fixed some stuff, if you want run the example, but now I have a consistent error across all three circuits: If you have any tips I can quickly fix this let me know, otherwise later I will dive deeper in the docs |
Pulling your most recent commits I am not seeing the errors you are mentioning, that being said those are certainly rust related and not RustQIP related, so RustQIP docs will not be helpful. If you're not familiar with the The second error you mentioned is just an undefined variable. I can improve the docs for
Where builder is an expression that evaluates to a mutable circuit builder (I will be more specific with type requirements in docs. The error you are describing is likely because you wrote r when r was not defined up to that point, so r didn't have the correct type (or any type). |
This is the first example with CSWAP. The new documentation was used (internally generated using
cargo doc --open
) and the layout of the old examples as wellIve started working on the dense_coding as well. However, I am faced with difficulty in using the
x, y, z
methods inside the match statements. For example I get this in the last three statements: