代做CMT304 Programming Paradigms 2025–26代做Python语言
- 首页 >> CSAssessment Proforma 2025–26
Key Information
|
Module Code |
CMT304 |
|
Module Title |
Programming Paradigms |
|
Assessment Title |
Functional, Differential and Quantum Programming |
|
Assessment Number |
Functional, Differential and Quantum Programming tasks of the portfolio coursework |
|
Assessment Weighting |
75% of the portfolio coursework. |
|
Assessment Limits |
Hand-out: 14th of October 2025 Hand-in: 8th of January 2026, 9:30am Feedback expected by: 5th of February 2026 Limits are per task as set in the instructions |
This assessment’s due date and time is specified on Learning Central. To view it click on the as- sessment’s link, which will open ‘Details & Information’ section for this assessment. Alternatively, go to ‘Calendar’ section of a module, and select ‘Due Dates’ option. You can change the view to daily or monthly, as well as use arrows to navigate the calendar.
The COMSC Assessment Calendar for all assessments is also available on Learning Central: by going to ‘COMSC-SCHOOL’organisation → ‘Assessment & Feedback 2025 – 26’folder → ‘COMSC Assessment Calendar 2025 – 26’ page.
1 Learning Outcomes
The learning outcomes for this assessment are
• Explain the conceptual foundations, evaluate and apply various programming paradigms, such as logic, functional, scripting, filter-based programming, pattern matching and quantum com- puting, to solve practical problems.
• Discuss and contrast the issues, features, design and concepts of a range of programming paradigms and languages to be able to select a suitable programming paradigm to solve a problem.
2 Submission Instructions
All assessment files should be submitted in ‘Assessment & Feedback’ folder on Learning Central.
Before you submit your assessment, you must complete and submit ‘Assessment Coversheet’ form. Further instructions are given in this module’s ‘Assessment & Feeback’ folder.
Your submission for this assessment should contain the following file(s):
|
Description |
Type |
Name |
|
|
Task 1 |
Compulsory |
One Haskell ( . hs) source file |
task1 . hs |
|
Task 2 |
Compulsory |
One Python (. py) source file |
task2 . py |
|
Task 3 |
Compulsory |
One Python (. py) source file |
task3 . py |
|
Task 4 |
Compulsory |
One PDF ( . pdf) file (max. 800 words) |
task4. pdf |
If you are unable to submit your work, email your submission to the module leader, coursework setter and [email protected]. If the technical is- sue is with Cardiff University systems, also report it to the University IT Support: email [email protected], tel. +44 (0)29 2251 1111.
Any code will be tested on a Linux system equivalent to COMSC’s Linux lab machines and must run there.
3 Assessment Description
Task 1: Write a Haskell function
latinSquares :: [[Int]] -> [[[Int]]]
that takes as input a partially filled n × n Latin square (a grid where each row and each column must contain the numbers 1 to n exactly once, and 0 represents an empty cell), and returns a list of all possible valid completions of the Latin square (each as a list of lists). If there are no solutions, the result should be the empty list. The function should work for any n ≥ 2.
Example:
- - Input (n = 4):
- - [ [1,0,0,4]
- - , [0,0,0,0]
- - , [0,0,0,0]
- - , [4,0,0,2] ]
--
- - Output (all possible solutions, e . g . ):
- - [ [1,2,3,4]
- - , [2,3,4,1]
- - , [3,4,1,2]
- - , [4,1,2,3] ]
- - . . . and possibly others
• Your function must be efficient and handle at least n = 6 in reasonable time. For n = 4 and n = 5, the function should complete quickly, while n = 6 should complete within a reasonable timeframe. (the exact time will depend on the specific constraints and hardware, but should not take excessively long, i.e., not tens of minutes).
• You must write clear comments explaining your approach, including the main algorithm, optimizations, and any problem-specific discussion, especially how you control the search and backtracking to find all solutions. Your code should be well-documented with comments that explain the purpose of key functions, the overall strategy, and any non-obvious imple- mentation details.
• You must not use any external libraries for solving Latin squares (standard Haskell 2010 li- braries only).
• You must provide at least three unit tests (as Haskell functions test1, test2, test3 that take no input and return a Bool) that demonstrate correctness for different n and edge cases, including cases with multiple and zero solutions. You may use HUnit and QuickCheck as used in the module, but note the requirement to strictly return a Bool for each test individually.
Task 2: Write a Python module that implements and compares two different models for fitting measurement data:
fit_analytic(time: np. ndarray, voltage: np. ndarray) -> callable
fit_nn(time: np. ndarray, voltage: np. ndarray) -> callable
Each function takes as input two numpy arrays: time (shape (N, )) and voltage (shape (N, )), corre- sponding to the measurement data in the provided measurements . csv file (first column: time, second column: voltage; N = 1000). The measurements . csv file is provided with this course- work specification. Each function should return a callable fp(t) that approximates the measurement data using differentiable programming techniques (PyTorch, TensorFlow, or JAX - use these libraries only and note this must follow a differentiable programming approach, nothing else). One model should be a custom analytical function (e.g., a sum of sinusoids or other parameterised form), and the other a small neural network. You must compare the two approaches and reflect on the trade- offs (e.g., performance, number of parameters, training stability) in your code comments. Do not use any external libraries for curve fitting beyond the allowed frameworks. Your code must be effi- cient and well-documented, with clear comments explaining your approach, optimisations, and any problem-specific discussion. Your code should be well-documented with comments that explain the purpose of key functions, the overall strategy, and any non-obvious implementation details.
File-reading logic (e.g., loading measurements. csv) should not be inside fit_analytic or fit_nn, but rather in the unit test functions. This ensures your functions are pure and match the required signatures.
• You must provide at least three unit tests (as Python functions test1, test2, test3 that take no input and return a Bool) that demonstrate correctness for different types of input data and edge cases. Your submitted unit tests should be self-contained: they should create their own synthetic numpy arrays as input to test your fitting functions, rather than reading from an external file. You should, of course, use the provided measurements . csv in a separate, non-submitted script. for your own development and for the analysis required for your code comments.
• Submit a single Python file containing your functions and tests. Do not submit output files or results.
• Do not submit measurements . csv. Your functions will be tested with a file of the same format but potentially different data (but with a similar type of 1D signal) to ensure your solution is robust.
• Assume measurements . csv is in the directory the Python file is executed from for your own testing, but your submission should only include the functions and tests.
Task 3: Write a Python function
identify_gate(simulate_circuit: callable) -> str
that, given the function
simulate_circuit(gate: str, input_state: str) -> list[float]
that you must also implement, can identify an unknown two-qubit gate G from a specified set of gates (specifically "I", "X", "Y", "Z", "H", "S", "T", "SWAP") by preparing suitable input states, simulat- ing the circuit, and analyzing the output measurement probabilities in the computational basis. The unknown gate G is guaranteed to be one of the specified gates and does not create entanglement: it is either a product of single-qubit gates (G = G1 ⊗ G2) or a non-entangling two-qubit gate such as SWAP. Your function should return the name of the identified gate as a string (e.g. "SWAP" or "ZX", etc.).
You must ensure that your identification strategy can distinguish not only the type of single-qubit gate (e.g., X, H, T, etc.) but also which qubit it was applied to (i.e., distinguish X ⊗ I from I ⊗ X that are specified as "XI" or "IX" in the input string). The gate naming convention follows the pattern where the first character represents the gate applied to the first qubit and the second character represents the gate applied to the second qubit. For example, "XI" means X ⊗ I (X gate on first qubit, identity on second), "IX" means I ⊗ X (identity on first qubit, X gate on second), and "ZX" means Z ⊗ X (Z gate on first qubit, X gate on second). The input_state string should be a valid quantum state in the computational basis, i.e., "00", "01", "10", "11", matching the order used for the gates, while the output should be a list of probabilities for the four possible measurement outcomes (in order of "00", "01", "10", "11").
• You may use any standard Python library and ‘numpy’ for your implementation. Do not use any external libraries for quantum computing.
• Your identify_gate function should handle edge cases gracefully. If the identification is ambiguous or fails, you should return a string indicating the issue (e.g., "UNKNOWN" or "AMBIGUOUS"). Your simulate_circuit function should handle invalid inputs appro- priately (e.g., invalid gate names or input states).
• You must provide at least three unit tests (as Python functions test1, test2, test3 that take no input and return a Bool) that demonstrate correctness for different gates and edge cases, including tests for your simulate_circuit function.
• Your code should be well-documented with comments that explain the purpose of key func- tions, the overall strategy, and any non-obvious implementation details.
• Submit a single Python file containing your function and tests. Do not submit output files or results.
Task 4: Write a single report (max. 800 words; content beyond this limit will not be used to decide the mark) comparing and reflecting on the programming paradigms used in the three coursework tasks:
• Functional programming for the Latin square solver (Haskell)
• Differentiable programming for signal data fitting (Python)
• Quantum programming for gate identification (Python) Your report should consist of four sections:
(1) Discuss one strength and one limitation of each paradigm as experienced in your implemen- tations.
(2) Compare how each paradigm approaches problem-solving, abstraction, and expressiveness.
(3) Explicitly link your reflections to the module’s stated learning outcomes, discussing how your experience with each paradigm contributed to achieving these outcomes. For example, you might discuss how functional programming helped you understand declarative problem- solving, how differentiable programming demonstrated the power of automatic differentia- tion, or how quantum programming introduced you to probabilistic computation and quan- tum algorithms.
Do not include program-specific technical details here; those should be explained in comments within your code files.
