macro_rules! register_expr {
(@splitter($acc:ident) $builder:expr, $name:ident $indices:expr; $($tail:tt)*) => { ... };
(@splitter($acc:ident) $builder:expr, $name:ident $indices:expr, $($tail:tt)*) => { ... };
(@splitter($acc:ident) $builder:expr, $name:ident; $($tail:tt)*) => { ... };
(@splitter($acc:ident) $builder:expr, $name:ident, $($tail:tt)*) => { ... };
(@joiner($remaining:ident) $builder:expr, $name:ident $indices:expr; $($tail:tt)*) => { ... };
(@joiner($remaining:ident) $builder:expr, $name:ident $indices:expr, $($tail:tt)*) => { ... };
(@joiner($remaining:ident) $builder:expr, $name:ident; $($tail:tt)*) => { ... };
(@joiner($remaining:ident) $builder:expr, $name:ident, $($tail:tt)*) => { ... };
(@name_tuple ($($body:tt)*) <- $name:ident $indices:expr; $($tail:tt)*) => { ... };
(@name_tuple ($($body:tt)*) <- $name:ident $indices:expr, $($tail:tt)*) => { ... };
(@name_tuple ($($body:tt)*) <- $name:ident; $($tail:tt)*) => { ... };
(@name_tuple ($($body:tt)*) <- $name:ident, $($tail:tt)*) => { ... };
(@func($builder:expr, $args:expr) ($($body:tt)*) <- $name:ident $indices:expr; $func:expr) => { ... };
(@func($builder:expr, $args:expr) ($($body:tt)*) <- $name:ident $indices:expr, $($tail:tt)*) => { ... };
(@func($builder:expr, $args:expr) ($($body:tt)*) <- $name:ident; $func:expr) => { ... };
(@func($builder:expr, $args:expr) ($($body:tt)*) <- $name:ident, $($tail:tt)*) => { ... };
(@registers_for_names ($($body:tt)*) <- $name:ident $indices:expr; $($tail:tt)*) => { ... };
(@registers_for_names ($($body:tt)*) <- $name:ident $indices:expr, $($tail:tt)*) => { ... };
(@registers_for_names ($($body:tt)*) <- $name:ident; $($tail:tt)*) => { ... };
(@registers_for_names ($($body:tt)*) <- $name:ident, $($tail:tt)*) => { ... };
($builder:expr, $($tail:tt)*) => { ... };
}
A helper macro for applying functions to specific qubits in registers.
Macro takes a &builder, a comma seperated list of qubits and optionally expressions which can be
referenced as &[u64]
- plus a closure which takes a &builder and tuple of registers and
returns a tuple of the same size.
Currently you cannot reuse registers, so ra
cannot be referenced more than once, if you would
like more qubits from the register just put all the indices together and split them out inside
the closure (or call register_expr!
again inside).
use qip::*;
let n = 3;
let mut b = OpBuilder::new();
let ra = b.register(n)?;
let rb = b.register(n)?;
let (ra, rb) = register_expr!(&mut b, ra, rb[1]; |b, (ra, rb)| {
let ra = b.not(ra);
let rb = b.not(rb);
Ok((ra, rb))
})?;
let r = b.merge(vec![ra, rb])?;