From e7d13f312379b280f5ca6a11b8b23722f08a9c8f Mon Sep 17 00:00:00 2001 From: mlodi-hqs Date: Thu, 10 Oct 2024 17:06:19 +0200 Subject: [PATCH] missing tests --- .../operations/operation_conversions.rs | 4 ++ .../single_qubit_gate_operations.rs | 64 +++++++++---------- .../operations/supported_version.rs | 8 +++ 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/qoqo/tests/integration/operations/operation_conversions.rs b/qoqo/tests/integration/operations/operation_conversions.rs index d1e25506..2d7d12ff 100644 --- a/qoqo/tests/integration/operations/operation_conversions.rs +++ b/qoqo/tests/integration/operations/operation_conversions.rs @@ -56,7 +56,9 @@ use test_case::test_case; #[test_case(Operation::from(SqrtPauliX::new(100)); "SqrtPauliX")] #[test_case(Operation::from(InvSqrtPauliX::new(100)); "InvSqrtPauliX")] #[test_case(Operation::from(SGate::new(1)); "SGate")] +#[test_case(Operation::from(InvSGate::new(1)); "InvSGate")] #[test_case(Operation::from(TGate::new(1)); "TGate")] +#[test_case(Operation::from(InvTGate::new(1)); "InvTGate")] #[test_case(Operation::from(Hadamard::new(3)); "Hadamard")] #[test_case(Operation::from(GPi::new(3, 0.1.into())); "GPi")] #[test_case(Operation::from(GPi2::new(3, 0.1.into())); "GPi2")] @@ -139,6 +141,8 @@ use test_case::test_case; #[test_case(Operation::from(CZQubitResonator::new(0, 1)); "CZQubitResonator")] #[test_case(Operation::from(SqrtPauliY::new(100)); "SqrtPauliY")] #[test_case(Operation::from(InvSqrtPauliY::new(100)); "InvSqrtPauliY")] +#[test_case(Operation::from(SXGate::new(1)); "SXGate")] +#[test_case(Operation::from(InvSXGate::new(1)); "InvSXGate")] fn test_conversion(input: Operation) { pyo3::prepare_freethreaded_python(); Python::with_gil(|py| { diff --git a/roqoqo/tests/integration/operations/single_qubit_gate_operations.rs b/roqoqo/tests/integration/operations/single_qubit_gate_operations.rs index f5adf621..b9fc3693 100644 --- a/roqoqo/tests/integration/operations/single_qubit_gate_operations.rs +++ b/roqoqo/tests/integration/operations/single_qubit_gate_operations.rs @@ -510,37 +510,37 @@ fn test_singlequbitgate_debug() { // /// Test alpha, beta, global phase of single qubit gates with the unitary matrix -// #[test_case(SingleQubitGateOperation::from(RotateX::new(0, CalculatorFloat::from(PI/3.0))); "RotateX")] -// #[test_case(SingleQubitGateOperation::from(RotateY::new(0, CalculatorFloat::from(PI/3.0))); "RotateY")] -// #[test_case(SingleQubitGateOperation::from(RotateZ::new(0, CalculatorFloat::from(PI/3.0))); "RotateZ")] -// #[test_case(SingleQubitGateOperation::from(PhaseShiftState0::new(0, CalculatorFloat::from(PI/2.0))); "phaseshiftstate0")] -// #[test_case(SingleQubitGateOperation::from(PhaseShiftState1::new(0, CalculatorFloat::from(PI/2.0))); "phaseshiftstate1")] -// #[test_case(SingleQubitGateOperation::from(GPi::new(0, CalculatorFloat::from(PI/2.0))); "gpi")] -// #[test_case(SingleQubitGateOperation::from(GPi2::new(0, CalculatorFloat::from(PI/2.0))); "gpi2")] -// #[test_case(SingleQubitGateOperation::from(PauliX::new(1)); "PauliX")] -// #[test_case(SingleQubitGateOperation::from(PauliY::new(1)); "PauliY")] -// #[test_case(SingleQubitGateOperation::from(PauliZ::new(1)); "PauliZ")] -// #[test_case(SingleQubitGateOperation::from(SqrtPauliX::new(100)); "SqrtPauliX")] -// #[test_case(SingleQubitGateOperation::from(InvSqrtPauliX::new(100)); "InvSqrtPauliX")] -// #[test_case(SingleQubitGateOperation::from(SGate::new(1)); "SGate")] -// #[test_case(SingleQubitGateOperation::from(InvSGate::new(1)); "InvSGate")] -// #[test_case(SingleQubitGateOperation::from(TGate::new(1)); "TGate")] -// #[test_case(SingleQubitGateOperation::from(InvTGate::new(1)); "InvTGate")] -// #[test_case(SingleQubitGateOperation::from(Hadamard::new(0)); "Hadamard")] -// #[test_case(SingleQubitGateOperation::from(RotateAroundSphericalAxis::new( -// 0, -// CalculatorFloat::from(PI/3.0), -// CalculatorFloat::from(PI/2.0), -// CalculatorFloat::from(PI/4.0))); "Rotation")] -// #[test_case(SingleQubitGateOperation::from(RotateXY::new( -// 0, -// CalculatorFloat::from(PI/3.0), -// CalculatorFloat::from(PI/4.0))); "RotationXY")] -// #[test_case(SingleQubitGateOperation::from(Identity::new(0)); "Identity")] -// #[test_case(SingleQubitGateOperation::from(SqrtPauliY::new(0)); "SqrtPauliY")] -// #[test_case(SingleQubitGateOperation::from(InvSqrtPauliY::new(0)); "InvSqrtPauliY")] +#[test_case(SingleQubitGateOperation::from(RotateX::new(0, CalculatorFloat::from(PI/3.0))); "RotateX")] +#[test_case(SingleQubitGateOperation::from(RotateY::new(0, CalculatorFloat::from(PI/3.0))); "RotateY")] +#[test_case(SingleQubitGateOperation::from(RotateZ::new(0, CalculatorFloat::from(PI/3.0))); "RotateZ")] +#[test_case(SingleQubitGateOperation::from(PhaseShiftState0::new(0, CalculatorFloat::from(PI/2.0))); "phaseshiftstate0")] +#[test_case(SingleQubitGateOperation::from(PhaseShiftState1::new(0, CalculatorFloat::from(PI/2.0))); "phaseshiftstate1")] +#[test_case(SingleQubitGateOperation::from(GPi::new(0, CalculatorFloat::from(PI/2.0))); "gpi")] +#[test_case(SingleQubitGateOperation::from(GPi2::new(0, CalculatorFloat::from(PI/2.0))); "gpi2")] +#[test_case(SingleQubitGateOperation::from(PauliX::new(1)); "PauliX")] +#[test_case(SingleQubitGateOperation::from(PauliY::new(1)); "PauliY")] +#[test_case(SingleQubitGateOperation::from(PauliZ::new(1)); "PauliZ")] +#[test_case(SingleQubitGateOperation::from(SqrtPauliX::new(100)); "SqrtPauliX")] +#[test_case(SingleQubitGateOperation::from(InvSqrtPauliX::new(100)); "InvSqrtPauliX")] +#[test_case(SingleQubitGateOperation::from(SGate::new(1)); "SGate")] +#[test_case(SingleQubitGateOperation::from(InvSGate::new(1)); "InvSGate")] +#[test_case(SingleQubitGateOperation::from(TGate::new(1)); "TGate")] +#[test_case(SingleQubitGateOperation::from(InvTGate::new(1)); "InvTGate")] +#[test_case(SingleQubitGateOperation::from(Hadamard::new(0)); "Hadamard")] +#[test_case(SingleQubitGateOperation::from(RotateAroundSphericalAxis::new( + 0, + CalculatorFloat::from(PI/3.0), + CalculatorFloat::from(PI/2.0), + CalculatorFloat::from(PI/4.0))); "Rotation")] +#[test_case(SingleQubitGateOperation::from(RotateXY::new( + 0, + CalculatorFloat::from(PI/3.0), + CalculatorFloat::from(PI/4.0))); "RotationXY")] +#[test_case(SingleQubitGateOperation::from(Identity::new(0)); "Identity")] +#[test_case(SingleQubitGateOperation::from(SqrtPauliY::new(0)); "SqrtPauliY")] +#[test_case(SingleQubitGateOperation::from(InvSqrtPauliY::new(0)); "InvSqrtPauliY")] #[test_case(SingleQubitGateOperation::from(SXGate::new(0)); "SXGate")] -// #[test_case(SingleQubitGateOperation::from(InvSXGate::new(0)); "InvSXGate")] +#[test_case(SingleQubitGateOperation::from(InvSXGate::new(0)); "InvSXGate")] fn test_alpha_beta_singlequbitgates(gate: SingleQubitGateOperation) { let alpha_r = gate.alpha_r(); let alpha_i = gate.alpha_i(); @@ -554,8 +554,6 @@ fn test_alpha_beta_singlequbitgates(gate: SingleQubitGateOperation) { SingleQubitGate::new(*qubit, alpha_r, alpha_i, beta_r, beta_i, global_phase); let test_matrix = singlequbitgate.unitary_matrix().unwrap(); - println!("cargo:warning=MATRIX{:?}", matrix); - println!("cargo:warning=TEST_MATRIX{:?}", test_matrix); let epsilon = 1e-12; for i in 0..2 { assert!((matrix[[0, i]] - test_matrix[[0, i]]).norm() < epsilon); @@ -2030,7 +2028,7 @@ fn test_singlequbitgate_mul_symb() { #[test_case(SingleQubitGateOperation::from(RotateY::new(0, CalculatorFloat::from("theta"))); "RotateY")] #[test_case(SingleQubitGateOperation::from(PauliX::new(0)); "PauliX")] #[test_case(SingleQubitGateOperation::from(PauliY::new(0)); "PauliY")] -#[test_case( SingleQubitGateOperation::from(PauliZ::new(0)); "PauliZ")] +#[test_case(SingleQubitGateOperation::from(PauliZ::new(0)); "PauliZ")] #[test_case(SingleQubitGateOperation::from(SqrtPauliX::new(0)); "SqrtPauliX")] #[test_case(SingleQubitGateOperation::from(InvSqrtPauliX::new(0)); "InvSqrtPauliX")] #[test_case(SingleQubitGateOperation::from(SGate::new(0)); "SGate")] diff --git a/roqoqo/tests/integration/operations/supported_version.rs b/roqoqo/tests/integration/operations/supported_version.rs index 503b1a0e..ae48a1de 100644 --- a/roqoqo/tests/integration/operations/supported_version.rs +++ b/roqoqo/tests/integration/operations/supported_version.rs @@ -364,3 +364,11 @@ fn test_version_1_13_0_gate_definition(operation: operations::Operation) { fn test_version_1_15_0_single_qubit_gate(operation: operations::SingleQubitGateOperation) { assert_eq!(operation.minimum_supported_roqoqo_version(), (1, 15, 0)); } + +#[test_case(operations::SingleQubitGateOperation::from(operations::InvTGate::new(0)); "SqrtPaInvTGateuliY")] +#[test_case(operations::SingleQubitGateOperation::from(operations::InvSGate::new(0)); "InvSGate")] +#[test_case(operations::SingleQubitGateOperation::from(operations::SXGate::new(0)); "SXGate")] +#[test_case(operations::SingleQubitGateOperation::from(operations::InvSXGate::new(0)); "InvSXGate")] +fn test_version_1_16_0_single_qubit_gate(operation: operations::SingleQubitGateOperation) { + assert_eq!(operation.minimum_supported_roqoqo_version(), (1, 16, 0)); +}