public void PartialUDT()
        {
            var target = new FreeQubit(0);
            var op     = new QuantumSimulator().Get <ICallable <(String, (Qubit, Double)), Circuits.FooUDT> >(typeof(Circuits.FooUDT))
                         .Partial <double>((double d) => (("bar", (target, d))));
            var args     = new QTuple <double>(2.1);
            var expected = new RuntimeMetadata()
            {
                Label = "FooUDT",
                FormattedNonQubitArgs = "(\"bar\", (" + 2.1 + "))",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void ControlledAdjointAdjointH()
        {
            IQArray <Qubit> controls = new QArray <Qubit>(new[] { new FreeQubit(0) });
            Qubit           target   = new FreeQubit(1);
            var             op1      = new QuantumSimulator().Get <Intrinsic.H>().Controlled.Adjoint.Adjoint;
            var             op2      = new QuantumSimulator().Get <Intrinsic.H>().Adjoint.Controlled.Adjoint;
            var             op3      = new QuantumSimulator().Get <Intrinsic.H>().Adjoint.Adjoint.Controlled;
            var             args     = op1.__DataIn__((controls, target));
            var             expected = new RuntimeMetadata()
            {
                Label = "H",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = true,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = controls,
                Targets  = new List <Qubit>()
                {
                    target
                },
            };

            Assert.Equal(op1.GetRuntimeMetadata(args), expected);
            Assert.Equal(op2.GetRuntimeMetadata(args), expected);
            Assert.Equal(op3.GetRuntimeMetadata(args), expected);
        }
        public void PartialRy()
        {
            var target = new FreeQubit(0);
            var op     = new QuantumSimulator().Get <Intrinsic.Ry>().Partial((double d) =>
                                                                             new ValueTuple <double, Qubit>(d, target));
            var args     = op.__DataIn__(2.1);
            var expected = new RuntimeMetadata()
            {
                Label = "Ry",
                FormattedNonQubitArgs = "(" + 2.1 + ")",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                    target
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void ControlledCCNOT()
        {
            Qubit           control1 = new FreeQubit(0);
            Qubit           control2 = new FreeQubit(1);
            Qubit           control3 = new FreeQubit(2);
            Qubit           target   = new FreeQubit(3);
            IQArray <Qubit> controls = new QArray <Qubit>(new[] { control1 });
            var             op       = new QuantumSimulator().Get <Intrinsic.CCNOT>().Controlled;
            var             args     = op.__DataIn__((controls, (control2, control3, target)));
            var             expected = new RuntimeMetadata()
            {
                Label = "X",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = true,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                    control1, control2, control3
                },
                Targets = new List <Qubit>()
                {
                    target
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void AdjointAdjointH()
        {
            Qubit target   = new FreeQubit(0);
            var   op       = new QuantumSimulator().Get <Intrinsic.H>().Adjoint.Adjoint;
            var   args     = op.__DataIn__(target);
            var   expected = new RuntimeMetadata()
            {
                Label = "H",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                    target
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void OperationAsArgument()
        {
            var q        = new FreeQubit(0);
            var opArg    = new QuantumSimulator().Get <Circuits.HOp>();
            var op       = new QuantumSimulator().Get <Circuits.WrapperOp>();
            var args     = op.__DataIn__((opArg, q));
            var expected = new RuntimeMetadata()
            {
                Label = "WrapperOp",
                FormattedNonQubitArgs = "(HOp)",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                    q
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void FooUDTOp()
        {
            Qubit target   = new FreeQubit(0);
            var   op       = new QuantumSimulator().Get <Tests.Circuits.FooUDTOp>();
            var   args     = op.__DataIn__(new Circuits.FooUDT(("bar", (target, 2.1))));
            var   expected = new RuntimeMetadata()
            {
                Label = "FooUDTOp",
                FormattedNonQubitArgs = "(\"bar\", (" + 2.1 + "))",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                    target
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void DuplicateQubitArgs()
        {
            var q        = new FreeQubit(0);
            var op       = new QuantumSimulator().Get <Circuits.TwoQubitOp>();
            var args     = op.__DataIn__((q, q));
            var expected = new RuntimeMetadata()
            {
                Label = "TwoQubitOp",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                    q
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void MResetZ()
        {
            var measureQubit = new FreeQubit(0);
            var op           = new QuantumSimulator().Get <Measurement.MResetZ>();
            var args         = op.__DataIn__(measureQubit);
            var expected     = new RuntimeMetadata()
            {
                Label = "MResetZ",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = true,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                    measureQubit
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void Swap()
        {
            var q1       = new FreeQubit(0);
            var q2       = new FreeQubit(1);
            var op       = new QuantumSimulator().Get <Intrinsic.SWAP>();
            var args     = op.__DataIn__((q1, q2));
            var expected = new RuntimeMetadata()
            {
                Label = "SWAP",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                    q1, q2
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void CNOT()
        {
            var control  = new FreeQubit(1);
            var target   = new FreeQubit(0);
            var op       = new QuantumSimulator().Get <Intrinsic.CNOT>();
            var args     = op.__DataIn__((control, target));
            var expected = new RuntimeMetadata()
            {
                Label = "X",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = true,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                    control
                },
                Targets = new List <Qubit>()
                {
                    target
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void ResetAll()
        {
            IQArray <Qubit> targets  = new QArray <Qubit>(new[] { new FreeQubit(0) });
            var             op       = new QuantumSimulator().Get <Intrinsic.ResetAll>();
            var             args     = op.__DataIn__(targets);
            var             expected = new RuntimeMetadata()
            {
                Label = "ResetAll",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = true,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = targets,
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void NestedOperation()
        {
            var op       = new QuantumSimulator().Get <Circuits.NestedOp>();
            var args     = op.__DataIn__(QVoid.Instance);
            var expected = new RuntimeMetadata()
            {
                Label = "NestedOp",
                FormattedNonQubitArgs = "",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }
        public void QArrayArgs()
        {
            var op = new QuantumSimulator().Get <Circuits.BoolArrayOp>();
            IQArray <Boolean> bits = new QArray <Boolean>(new bool[] { false, true });
            var args     = op.__DataIn__(bits);
            var expected = new RuntimeMetadata()
            {
                Label = "BoolArrayOp",
                FormattedNonQubitArgs = "[False, True]",
                IsAdjoint             = false,
                IsControlled          = false,
                IsMeasurement         = false,
                IsComposite           = false,
                Children = null,
                Controls = new List <Qubit>()
                {
                },
                Targets = new List <Qubit>()
                {
                },
            };

            Assert.Equal(op.GetRuntimeMetadata(args), expected);
        }